I'm creating a simple game loop in an Android app....
# coroutines
m
I'm creating a simple game loop in an Android app. I was just about to start writing this in a classic way with SurfaceView that holds and manages a Thread object. But we're in a world of coroutines now coroutine so why not use them also in this use-case. Do you see any potential downsides or problems with it? I'm doing something similar to this tutorial https://riptutorial.com/android/example/30741/game-using-canvas-and-surfaceview so some canvas locking, unlocking, looping and drawing
e
I'm not well aware of the details of those Android APIs, but I can imagine that this looping and state reading + writing must happen on one thread only. Therefore, what comes to mind is https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/new-single-thread-context.html
👍 1
m
That's a good point. I was thinking about doing this on the main thread and switching context for heavier operations like bitmap manipulation