<分区>
我的场景中的一个节点似乎有问题。
我有一个按钮:
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()
但是,在攻击按钮出现的区域,一旦它被移除,该区域仍然可以点击。
有什么想法吗?