2016-01-04 70 views
0

我有這個功能,我想在遊戲結束後將其刪除。我嘗試使用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

http://stackoverflow.com/questions/22037223/stop-skaction-that-repeatsforever-sprite-kit –

+0

我試着func保持奔跑。 – coding22

+0

當你添加動作時,你可能應該設置一個你可以用來刪除動作的鍵,比如'runAction(endlessAction,withKey:「myKey1」)' –

回答

2

runAction(endlessAction, withKey: "endlessAction1")

更換runAction(endlessAction)然後調用

removeActionForKey("stop") 
removeActionForKey("endlessAction1") 

,你想讓它停下來。

+0

它的作品謝謝你! – coding22

+0

我以爲我不得不停止功能,而不是功能內的動作。 – coding22

相關問題