简体   繁体   English

重新开始滑行顺序

[英]Restart skaction sequence

in my game, I have a skaction sequence where i use waitForDuration first, and do something else after. 在我的游戏中,我有一个动作序列,在该序列中,我先使用waitForDuration,然后再进行其他操作。 The problem is that when the user loses, I need the sequence to restart from the beginning, with waitForDuration. 问题是,当用户迷路时,我需要使用waitForDuration从头开始重新启动序列。 Does anyone know of a way to reset the sequence inside didMoveToView? 有谁知道重置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. 理想情况下,您可以将动画存储在属性中,并在需要时运行它,而不必每次都重新生成它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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