Modify a repeating task sequence while running

拜拜、爱过 提交于 2019-12-04 19:36:50

when you create actionwait it's going to save the values inside that closure and keep using them in your repeatActionForever

When you're tracking changes it's best to do that sort of thing in the update method. Using actions in this case might not be the best approach.

I'm not sure about when you (for your game) need to be checking for changes. For most things using the update method is adequate

heres one way i implement a timer in update

// MY TIMER PROPERTIES IN MY CLASS
var missleTimer:NSTimeInterval = NSTimeInterval(2)
var missleInterval:NSTimeInterval = NSTimeInterval(2)


// IN MY UPDATE METHOD
self.missleTimer -= self.delta

if self.missleTimer <= 0 {  // TIMER HIT ZERO, DO SOMETHING!
    self.launchMissle()  // LAUNCH MY MISSLE
    self.missleTimer = self.missleInterval  // OKAY LETS RESET THE TIMER
}

delta is the difference of time between this frame and the last frame. It's used create fluid motion, and track time. Things like that. This is pretty standard among spritekit projects. you usually need to use delta projectwide

declare these two properties:

// time values
var delta:NSTimeInterval = NSTimeInterval(0)
var last_update_time:NSTimeInterval = NSTimeInterval(0)

This should be how the top of your update method looks

func update(currentTime: NSTimeInterval) {
    if self.last_update_time == 0.0 
        self.delta = 0
    } else {
        self.delta = currentTime - self.last_update_time
    }

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