Skip to content

Instantly share code, notes, and snippets.

@ariefannur
Created February 13, 2018 08:43
Show Gist options
  • Save ariefannur/8035768dc8b4a745d8e310616a707771 to your computer and use it in GitHub Desktop.
Save ariefannur/8035768dc8b4a745d8e310616a707771 to your computer and use it in GitHub Desktop.
game engine timer kotlin
class GameEngine {
// time length 20 s
val TIME_UNIT: Long = 21000
var timer:CountDownTimer? = null
fun init(state: GameState){
state.onStartEngine()
// interval 1 s
timer = object : CountDownTimer(TIME_UNIT, 1000){
override fun onFinish() {
state.onFinish()
}
override fun onTick(p0: Long) {
state.onUpdate(p0)
}
}
}
fun start(){
timer?.start()
}
fun stop(){
timer?.cancel()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment