我正在制作一个蓬松的鸟克隆,当鸟死时,弹出带有重新启动按钮的 spriteNode,但第一次单击正在停止动画(如果有的话),第二次单击是重新启动()功能
下面是我如何使用按钮制作 SpriteNode 菜单:
let menu = SKSpriteNode(texture: self.groundTex)
menu.name = "menu"
menu.position = CGPoint(x: 0, y: 0)
menu.zPosition = 20
let restartButton = SKSpriteNode(texture: self.heroTexture)
restartButton.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));
restartButton.zPosition = 40
restartButton.name = "restart"
let moveMenu = SKAction.moveTo(CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2), duration: 1.0)
self.menuNode.addChild(menu)
menuNode.addChild(restartButton)
self.addChild(menuNode)
menu.runAction(SKAction.sequence([
moveMenu,
SKAction.waitForDuration(NSTimeInterval(1.0)),
makeGameEnd
]), withKey: "gameover"
这是我检测触摸的方式:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first
let location = touch?.locationInNode(self)
let node: SKNode = nodeAtPoint(location!)
if node.name == "restart" {
restart()
}
更新 我的重启():
func restart() {
let scene = GameScene(size: self.size)
scene.scaleMode = .AspectFill
self.view?.presentScene(scene)
}