0

ゆるい鳥のクローンを作成し、鳥が死ぬと、再起動ボタン付きの spriteNode がポップアップしますが、最初のクリックでアニメーションが停止し (存在する場合)、2 回目のクリックで restart() 関数が実行されます。

ボタン付きの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)
}
4

1 に答える 1

0

このようなダブルタップを確認できます

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    let touch  = touches.first
    let location = touch?.locationInNode(self)
    let node: SKNode = nodeAtPoint(location!)

if touch.tapCount % 2 == 0 {

    if node.name == "restart" {
       restart()
    }
}
}
于 2015-12-03T19:12:20.943 に答える