Swift + SpriteKit - 即使不可见,按钮也是可点击的

时间:2016-04-10 23:19:18

标签: swift sprite-kit sknode

我似乎在我的场景中有一个节点出现问题。

我有一个按钮:

 func createAttackButton() {
    attackButton.zPosition = 1
    attackButton.anchorPoint = CGPointZero
    attackButton.position = CGPointMake(20, 20)
    attackButton.size = CGSize(width: 150, height: 40)

    addChild(attackButton)

 }

与敌人接触时调用此功能。

要从此按钮运行一个函数,我使用touchesBegan()函数:

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

    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        if attackButton.containsPoint(location) {

            print("Attack Button Clicked")

        }
    }
}

一旦敌人被摧毁,我将删除攻击按钮节点:

 attackButton.removeFromParent()

但是,在出现攻击按钮的区域中,一旦删除该区域,该区域仍然可以点击。

有什么想法吗?

0 个答案:

没有答案