我有這個功能,我想在遊戲結束後將其刪除。我嘗試使用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")
}
}
}
http://stackoverflow.com/questions/22037223/stop-skaction-that-repeatsforever-sprite-kit –
我試着func保持奔跑。 – coding22
當你添加動作時,你可能應該設置一個你可以用來刪除動作的鍵,比如'runAction(endlessAction,withKey:「myKey1」)' –