Hi! Currently looking at creating a multiplayer ga...
# korge
m
Hi! Currently looking at creating a multiplayer game with Korge. I wanted to interpolate player positions between server updates to make the movement smooth. I tried using Tween to do the interpolation. This led me to create a new tween for each interpolation. But it didnt really work as the tween sometimes overlapped. Ended up creating my own InterpolationTween without coroutine parts and method to update start and stop variables. What do you think about this? Is there any good way to do this without creating my new Tween? Here is the whole project if you want more context: https://github.com/maxonline/KotlinJsJvmGame/tree/korge
d
I think properties are not checked for newer tweens right now with the current implementation. Don't remember the full details. There is an Animator class that I believe supports cancelation and stuff. Have you checked that one? Is your tween API-compatible with the current tween and fixes the problems you described?
t
I had the same problem in my https://github.com/TobseF/MagicMaze-Island also a JS-Client-Server game. It's a board game adaption. Players move one field on a board. The movement is animated. But when a player is in hurry he can move to the next field, before the first animation is finished. I solved it in this way:
Copy code
addJob(stage.launch {
	hero.moveTo(nextPos.x, nextPos.y, 260.milliseconds, EASE_IN_OUT_QUAD)
}, hero.hero)
So I run every move animation inside a corutine. To cancel a running Job, before starting the next one, all jobs are stored in a list:
Copy code
fun addJob(job: Job, hero: Team.Hero) {
    val mutableList = animations[hero.number]!!
    mutableList.forEach { it.cancel() }
    mutableList.clear()
    mutableList.add(job)
    job.invokeOnCompletion {
        mutableList.clear()
    }
}
A new job, cancels all in the list, and clears it. This was my workaround, of the moveto tween which was not canceable (because it retuns no job).
m
@Deactivated User Depends on what you call Api-compatible. It works as the regular tween except it has no call backs or coroutine stuff so the
BaseView?.tween( .. )
is no longer
suspend
. Otherwise it works the same. Will checkout the Animator class. But my guess is that i will still use my new tween as it fits my purpose very good
👍 1
d
Yeah. In the end KorGE is just a base with some additional utils that might work your use-case or not. But it is pretty extensible, so if that component works for you. Awesome! Also if you believe your code is reusable enough there are two ways for sharing it with other people: • https://awesome.korge.org/ • Or making a PR to korge-next itself if you think it is general enough to be part of the core of the engine