[英]Sprite Kit Scene won't present
I am currently working on a game that consists of three scenes, the GameScene, ArcheryScene, and GameOverScene. 我目前正在开发一个由三个场景组成的游戏,即GameScene,ArcheryScene和GameOverScene。 When I start the game the GameScene presents just fine, then I tap on the screen to start the game and the ArcheryScene presents just fine.
当我开始游戏时,GameScene呈现良好,然后点击屏幕以启动游戏,而ArcheryScene呈现良好。 The GameOverScene gets triggered when a contact is made in the game, and it works as well.
在游戏中建立联系时会触发GameOverScene,它也可以正常工作。 However, once the GameOverScene is presented I would like to be able to tap on the screen to go back to the ArcheryScene and restart the game.
但是,一旦出现GameOverScene,我希望能够在屏幕上点击以返回ArcheryScene并重新启动游戏。 However when I tap on the screen, nothing happens, at all.
但是,当我点击屏幕时,什么也没有发生。 Any advice or suggestions would be great appreciated, thank you.
任何意见或建议将不胜感激,谢谢。
GameScene Code that presents the ArcheryScene when tapped: (works) 点按时显示ArcheryScene的GameScene代码:(有效)
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 code that presents the GameOverScene when a contact is made: (works) 建立联系时显示GameOverScene的ArcheryScene代码:(有效)
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 that presents the ArcheryScene when tapped: (doesn't work) 点按时显示ArcheryScene的GameOverSceneCode :(无效)
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 */
}
}
gameOverNode doesnt exist. gameOverNode不存在。 Youre saying
let gameOverNode = childNodeWithName("gameOverNode")
.. gameOverNode is nil! 您是说
let gameOverNode = childNodeWithName("gameOverNode")
.. gameOverNode为零! It's nothing, and so that block of code in the conditional statement isnt doing anything. 没什么,所以条件语句中的代码块什么也做不了。
you need to add a node named "gameOverNode" in order to reference it. 您需要添加一个名为“ gameOverNode”的节点才能对其进行引用。
childNodeWithName
references a node that already exists in your scene.. its not creating a new one. childNodeWithName
引用场景中已经存在的一个节点。它没有创建一个新节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.