所以我在我的GameScene中有这个功能,它是2级的按钮,它在我的GameScene中出现的唯一方式是在我的level1Scene中HeroCategory和GoldKeyCategory之间发生联系。当这两个类别之间发生联系时,我如何调用levelTwoButton函数?那有意义吗?我现在有点困难,需要帮助。谢谢!
编辑:我想在我的GameScene中显示2级按钮,因为那是我的主菜单,而不是level1Scene。// GameScene
func unlockLevelTwo() {
let fadeIn = SKAction.fadeInWithDuration(1.0)
levelTwoButton.position = CGPointMake(self.size.width / 2.0, self.size.height / 2.2)
levelTwoButton.zPosition = 20
levelTwoButton.setScale(0.8)
levelTwoButton.alpha = 0
levelTwoButton.runAction(fadeIn)
levelTwoButton.name = "leveltwobutton"
addChild(levelTwoButton)
}
//levelScene
if firstBody.categoryBitMask == HeroCategory && sixthBody.categoryBitMask == GoldKeyCategory{
GameScene().unlockLevelTwo()
runAction(playLevelCompleteSound)
println("you win and level two button unlocked in the main menu!!!!!")
}
答案 0 :(得分:1)
你可以使用记住你的精灵碰撞的NSUserDefaults
,就像你可以存储它的levelScene
一样:
if firstBody.categoryBitMask == HeroCategory && sixthBody.categoryBitMask == GoldKeyCategory{
GameScene().unlockLevelTwo()
runAction(playLevelCompleteSound)
println("you win and level two button unlocked in the main menu!!!!!")
NSUserDefaults().setBool(true, forKey: "Leavel2")
}
之后,在GameScene
方法的didMoveToView
中,每当您的视图以这种方式加载时,请阅读
override func didMoveToView(view: SKView) {
/* Setup your scene here */
let unlockLeavel2 = NSUserDefaults().boolForKey("Leavel2")
if unlockLeavel2 {
unlockLevelTwo()
}
}
即使你退出app,这也会存储。
希望这会有所帮助。