我目前正在开发一款由三个场景组成的游戏,GameScene,ArcheryScene和GameOverScene。当我开始游戏时GameScene呈现得很好,然后我点击屏幕开始游戏,ArcheryScene呈现得很好。 GameOverScene会在游戏中建立联系时触发,并且也可以。然而,一旦呈现GameOverScene,我希望能够点击屏幕返回ArcheryScene并重新开始游戏。然而,当我点击屏幕时,根本没有任何反应。任何建议或建议都将非常感谢,谢谢。
GameScene Code在点击时显示ArcheryScene :(有效)
import UIKit
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
let welcomeNode = childNodeWithName("welcomeNode")
if (welcomeNode != nil) {
let fadeAway = SKAction.fadeOutWithDuration(1.0)
welcomeNode?.runAction(fadeAway, completion: {
let doors = SKTransition.pushWithDirection(SKTransitionDirection.Down, duration: 1.0)
let archeryScene = ArcheryScene(fileNamed: "ArcheryScene")
archeryScene.scaleMode = .AspectFill
self.view?.presentScene(archeryScene, transition: doors)
})
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
ArcheryScene代码,用于在联系人时显示GameOverScene :(有效)
let fadeOut = SKAction.sequence([SKAction.waitForDuration(3.0)])
let welcomeReturn = SKAction.runBlock({
let Transition = SKTransition.revealWithDirection(SKTransitionDirection.Down, duration: 1.0)
let gameOverScene = GameScene(fileNamed: "GameOverScene")
gameOverScene.scaleMode = .AspectFill
self.scene!.view?.presentScene(gameOverScene, transition: Transition)
})
let sequence = SKAction.sequence([fadeOut, welcomeReturn])
self.runAction(sequence)
GameOverSceneCode在点击时显示ArcheryScene :(不起作用)
import UIKit
import SpriteKit
class GameOverScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
let gameOverNode = childNodeWithName("gameOverNode")
if (gameOverNode != nil) {
let fadeAway2 = SKAction.fadeOutWithDuration(1.0)
gameOverNode?.runAction(fadeAway2, completion: {
let doors2 = SKTransition.pushWithDirection(SKTransitionDirection.Down, duration: 1.0)
let archeryScene = ArcheryScene(fileNamed: "ArcheryScene")
archeryScene.scaleMode = .AspectFill
self.view?.presentScene(archeryScene, transition: doors2)
})
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
答案 0 :(得分:0)
gameOverNode不存在。你说let gameOverNode = childNodeWithName("gameOverNode")
.. gameOverNode是零!它什么都没有,所以条件语句中的代码块没有做任何事情。
您需要添加名为“gameOverNode”的节点才能引用它。 childNodeWithName
引用场景中已存在的节点..它不会创建新节点。