Created
February 13, 2018 08:43
-
-
Save ariefannur/8035768dc8b4a745d8e310616a707771 to your computer and use it in GitHub Desktop.
game engine timer kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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