0

I have this function and I want to remove it once the game is over. I tried using removeActionWithKey but that doesn't seem to work. Is there another way I could remove it once the game is over?

 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")


        }

    }
}
coding22
  • 689
  • 1
  • 7
  • 28

1 Answers1

2

replace runAction(endlessAction) with runAction(endlessAction, withKey: "endlessAction1")

then call

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

where you want it to stop.

John Boker
  • 82,559
  • 17
  • 97
  • 130