使用touchBegan添加按钮

时间:2016-02-16 01:04:00

标签: swift button sprite-kit xcode7 touchesbegan

我在玩GitHub的Swift游戏。我正在尝试向touchesBegan(newButton)添加另一个按钮。这是我到目前为止所得到的:

root@abc:~# cat /proc/8443/status
Name:   abcdd
State:  S (sleeping)
Tgid:   8443
VmSwap:        0 kB
Threads:    4
SigQ:   0/256556
SigPnd: 0000000000000000

以下是按钮的代码:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    guard !gameOver else {
        let gameOverLayer = childNodeWithName(StickHeroGameSceneChildName.GameOverLayerName.rawValue) as SKNode?
        let location = touches.first?.locationInNode(gameOverLayer!)
        let retry = gameOverLayer!.nodeAtPoint(location!)
        if (retry.name == StickHeroGameSceneChildName.RetryButtonName.rawValue) { 
            print("Retry")
            NSNotificationCenter.defaultCenter().postNotificationName("hideBanner", object: nil)
            retry.runAction(SKAction.sequence([SKAction.setTexture(SKTexture(imageNamed: "button_retry_down"), resize: false), SKAction.waitForDuration(0.3)]), completion: {[unowned self] () -> Void in
                self.restart()
            })   
        }
        return
    }
    guard !gameOver else {
        let gameOverLayer2 = childNodeWithName(StickHeroGameSceneChildName.GameOverLayerName.rawValue) as SKNode?
        let location2 = touches.first?.locationInNode(gameOverLayer2!)
        let games = gameOverLayer2!.nodeAtPoint(location2!)
        if (newButton.name == StickHeroGameSceneChildName.GamesButtonName.rawValue) { 
            print("New Button")
        }
    }
    return
}

有GitHub:https://github.com/phpmaple/Stick-Hero-Swift 我在Swift很新,需要一些指导。感谢。

0 个答案:

没有答案