简体   繁体   English

如何在SKAction序列中更改变量?

[英]How to change variable within SKAction sequence?

When my viewDidLoad gets called, I run the following action: 当我的viewDidLoad被调用时,我运行以下操作:

    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". 然后,在我的更新方法中,将“ waitDuration”减少1。问题是序列继续运行,但是从不使用更新的“ 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")
}

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

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