Skip to content

Instantly share code, notes, and snippets.

@lucasprag
Created January 29, 2016 12:46
Show Gist options
  • Save lucasprag/569531414eb059d58185 to your computer and use it in GitHub Desktop.
Save lucasprag/569531414eb059d58185 to your computer and use it in GitHub Desktop.
Handle the time
// omitted
class GameScene: SKScene {
// omitted
// timers
var lastTime = 0
var currentTime = 0
override func update(delta: CFTimeInterval) {
// loop all enemies and make then walk to collide with the plyer
for enemy in enemies {
enemy.position = CGPoint(x: Double(enemy.position.x) - 5, y: Double(enemy.position.y))
}
currentTime = Int(delta)
if (lastTime == 0) {
lastTime = currentTime
}
if (currentTime > (lastTime + 1)) {
lastTime = currentTime
spawEnemy()
}
}
// omitted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment