Change time interval in SKAction.waitForDuration() as game goes on

你说的曾经没有我的故事 提交于 2019-12-02 08:19:11

You can use the recursive way to accomplish what you want (increment duration of wait parameter):

class GameScene:SKScene {

    var wait:NSTimeInterval = 0

    override func didMoveToView(view: SKView) {

        NSLog("Start") //Using NSLog just to print the current time
        recursive()

    }

    func recursive(){

        let recursive = SKAction.sequence([

            SKAction.waitForDuration(++wait),
            //Do your stuff here, eg. run scale, move...
            SKAction.runBlock({[unowned self] in NSLog("Block executed"); self.recursive()})
            ])

        runAction(recursive, withKey: "aKey")
    }
}

What you are currently experiencing, is that wait action is created, initialized and reused in an action sequence. You have to rebuild an action each time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!