https://kotlinlang.org logo
#korge
Title
# korge
v

voddan

04/25/2021, 9:09 AM
I need to perform animation on collision:
Copy code
box.onCollision {
  view.tween(...)
}
How do I pass the coroutine context there? Is there something like
box.onCollisionSuspended {..}
?
Copy code
launchImmediately(Dispatchers.Default) {
works, I guess
d

Deactivated User

04/26/2021, 10:52 AM
You shouldn't use
Dispatchers.Default
since KorGE has its own dispatcher, and that would use a different thread and you might have issues on some targets, you should propagate the coroutineContext of either the views, or a scene (that would handle its lifecycle)
v

voddan

05/02/2021, 2:43 PM
Could you give me an example of how would I access the
views
singleton from a random place in the program?
d

Deactivated User

05/02/2021, 4:40 PM
You can't. You have to propagate views, or an instance containing views. For example scenes contain views. If you have a suspend function, you can access the vies with
views()
the coroutine context if propagated properly should have the injector referenced
2 Views