在Swift Spritekit的Level1场景中出现联系人时,如何在游戏场景中运行函数?

在Swift Spritekit的Level1场景中出现联系人时,如何在游戏场景中运行函数?,swift,skscene,Swift,Skscene,因此,我的游戏场景中有这个功能,它是2级的一个按钮,它出现在游戏场景中的唯一方式是在我的1级场景中HeroCategory和GoldKeyCategory之间发生接触时。当这两个类别之间发生接触时,我将如何调用levelTwoButton函数?这有意义吗?我现在有点困了,需要帮助。谢谢 编辑:我希望2级按钮出现在我的游戏场景中,因为那是我的主菜单,而不是1级场景 // GameScene func unlockLevelTwo() { let fadeIn = SKAction.fadeIn

因此,我的游戏场景中有这个功能,它是2级的一个按钮,它出现在游戏场景中的唯一方式是在我的1级场景中HeroCategory和GoldKeyCategory之间发生接触时。当这两个类别之间发生接触时,我将如何调用levelTwoButton函数?这有意义吗?我现在有点困了,需要帮助。谢谢

编辑:我希望2级按钮出现在我的游戏场景中,因为那是我的主菜单,而不是1级场景

// 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!!!!!")
}

您可以使用
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")

}
之后,在您的
游戏场景中
在您的
didMoveToView
方法中,每次以这种方式加载视图时,请阅读:

 override func didMoveToView(view: SKView) {
    /* Setup your scene here */
    let unlockLeavel2 = NSUserDefaults().boolForKey("Leavel2")

    if unlockLeavel2 {

        unlockLevelTwo()
    }
}
即使您退出应用程序,此功能也会存储


希望这会有所帮助。

我现在就试试,告诉你是否有效……谢谢!哥们,它工作得很好。太谢谢你了……我大概三天都想不出来了。