简体   繁体   中英

Restart skaction sequence

in my game, I have a skaction sequence where i use waitForDuration first, and do something else after. The problem is that when the user loses, I need the sequence to restart from the beginning, with waitForDuration. Does anyone know of a way to reset the sequence inside didMoveToView?

override func didMoveToView(view: SKView) {

        var wait = SKAction.waitForDuration(15)
        let secondAction = SKAction.sequence([wait, SKAction.runBlock({() in self.addSecond(0.8)})])
        self.runAction(secondAction, completion: {println("second done")})
}

 func addSecond(waitDuration: NSTimeInterval) {

        var move = SKAction.runBlock({() in self.createTargets()})
        var wait = SKAction.waitForDuration(waitDuration)
        var moveAndWait = SKAction.repeatActionForever(SKAction.sequence([move, wait]))
        self.runAction(moveAndWait, withKey: "movingAction2")   
    }

remove all action from the object by calling:

[object removeAllActions]

and then start the animation again. Ideally, you can store the animation in a property and the run it when you need it instead pf regenerate it every time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM