我有这个功能,我想在游戏结束后删除它。我尝试使用removeActionWithKey,但似乎没有用。一旦游戏结束,还有其他方法可以删除吗?
func doAction() {
let generateCircles = SKAction.sequence([
SKAction.runBlock(self.circleRandom),
SKAction.waitForDuration(1.5)])
let endlessAction = SKAction.repeatActionForever(generateCircles)
runAction(endlessAction)
}
if firstBody.categoryBitMask == HeroCategory && secondBody.categoryBitMask == RedCategory {
//Tried to remove the func here but that doesn't work.
removeActionForKey("stop")
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
touchingScreen = false
if let touch = touches.first {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if node.name == "start" {
startGame.removeFromParent()
//Calling the doAction func here once start button is pressed.
let action = SKAction.runBlock(doAction)
runAction(action, withKey: "stop")
}
}
}
答案 0 :(得分:2)
将runAction(endlessAction)
替换为runAction(endlessAction, withKey: "endlessAction1")
然后致电
removeActionForKey("stop")
removeActionForKey("endlessAction1")
你希望它停止的地方。