Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brynbellomy/updatetimer
Scene update loop timer for SpriteKit, et al. (in Swift)
https://github.com/brynbellomy/updatetimer
Last synced: 23 days ago
JSON representation
Scene update loop timer for SpriteKit, et al. (in Swift)
- Host: GitHub
- URL: https://github.com/brynbellomy/updatetimer
- Owner: brynbellomy
- License: wtfpl
- Created: 2015-01-11T02:38:22.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-11T02:38:31.000Z (almost 10 years ago)
- Last Synced: 2024-10-04T20:37:26.677Z (about 1 month ago)
- Language: Swift
- Homepage:
- Size: 117 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# UpdateTimer
`UpdateTimer` is a simple `struct` that tracks commonly-needed chronological variables in the scene loop of a game. It currently exposes:
- Time since last update
- Time since first update
- Total frame count (number of times `update()` has been called)## lap timer
`UpdateTimer` also includes a lap timer that makes it trivial to track an arbitrary event (i.e., one that doesn't necessarily happen every `update()` cycle). During your scene loop's `update()` method, `timeSinceLastLap` will be set to the number of seconds since the previous time `lap()` was called (or, if it has never been called, the number of seconds since the first call to `update()`). Call `lap()` any time the event you're monitoring occurs, and `timeSinceLastLap` will reset to 0 and begin counting up again.
```swift
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
}
}
}
```# authors / contributors
bryn austin bellomy < >