UpdateTimer 0.0.1

UpdateTimer 0.0.1

测试已测试
语言语言 SwiftSwift
许可 WTFPL
发布最后发布2015年1月
SPM支持SPM

Bryn Austin Bellomy维护。



  • bryn austin bellomy

UpdateTimer是一个简单的struct,它跟踪游戏场景循环中常用的时间变量。它目前公开:

  • 自上次更新以来时间
  • 自第一次更新以来时间
  • 总帧计数(调用update()的次数)

圈速计时器

UpdateTimer还包括一个圈速计时器,可以非常容易地跟踪任意事件(例如,不必在每个update()周期发生的事件)。在您场景循环的update()方法期间,timeSinceLastLap将设置为自上次调用lap()以来经过的秒数(如果尚未调用,则为自第一次调用update()以来经过的秒数)。在任何您要监控的事件发生时调用lap(),然后timeSinceLastLap将重置为0并重新开始计数。

class MyScene: SKScene
{
    let spawnMonsterInterval: NSTimeInterval = 5
    private var updateTimer = UpdateTimer()

    func update(currentTime:NSTimeInterval) {
        updateTimer.update(currentTime)

        println("seconds since last update() = \(updateTimer.timeSinceLastUpdate)")
        println("seconds since first update() = \(updateTimer.timeSinceFirstUpdate)")
        println("seconds since monster was spawned = \(updateTimer.timeSinceLastLap)")
        println("number of times update() has been called = \(updateTimer.frameCount)")

        if updateTimer.timeSinceLastLap >= spawnMonsterInterval {
            spawnMonster()
            updateTimer.lap()           // resets `timeSinceLastLap` to zero
        }
    }
}

作者 / 贡献者

bryn austin bellomy < [email protected] >