简体   繁体   中英

How to change variable within SKAction sequence?

When my viewDidLoad gets called, I run the following action:

    runAction(SKAction.repeatActionForever(
        SKAction.sequence([
            SKAction.runBlock(chainsawDropper),
            SKAction.waitForDuration(waitDuration)
            ])
        ))

Then in my update method I decrease the "waitDuration" by 1. The problem is that the sequence continues to run but never uses the updated "waitDuration". How can I achieve this?

if you run the action with a tag then you can override it at any time:

func updateActionForDuration(duration:NSTimeInterval) {
    self.runAction(  SKAction.repeatActionForever(SKAction.sequence(
         [SKAction.runBlock(chainsawDropper),
         SKAction.waitForDuration(duration)])), 
    withKey: "action key")
}

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