Reputation: 585
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")
}
Upvotes: 1
Views: 421
Reputation: 8629
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.
Upvotes: 1