I have a issue with tweens when working with korge...
# korge
m
I have a issue with tweens when working with korge-js:
Copy code
val view = SolidRect(width = 20.0, height = 5.0, color = Colors.RED)
view.tween(view::x[10.0, 100.0], time = 1000.milliseconds)
view.tween(*view::x*[10.0, 100.0], ...) does not work as view.x is Koltin.Double and not KMutableProperty Am i doing something wrong or does this not work when i am using korge-js and not the common api?
d
Hey Max, is that the whole code? You are creating the view but not adding it to the stage or any other view. Tweening is a component that is only executed when the receiver view is attached to the stage. Have you tried the code on the JVM target?
m
here is the code: https://github.com/maxonline/KotlinJsJvmGame/blob/korge/src/jsMain/kotlin/maxonline.client/Game.kt#L86 Not tried it with the JVM target. It is a compilation error
(code is a bit broken at the current state)
d
Yeah it has JS specific code. If the view is not on the stage, that would freeze the onMessage function. Also tween is suspending the function. Not sure if you want to execute all the tweens in parallel or sequentially. Right now it is sequential. As a quick test, try to pass the stage to the onMessage function and change: view.tween(view::x...) -> println(“${view.root} ${view}”) stage.tween(view::x...) By using stage as receiver you are sure that the tween will end even if the view is not visible. With the print you can check if the view's root is the stage (and thus potentially visible)
m
Ill try that but I am still geting this:
I thought the tween would just add som code to the update() of that view and would move the object in future frame updates. I guess i have to read up on how tweens work 😊
j
I'm still very much a korge newbie but I don't think tween supports 2 values (you have 10 and 100). If you want two steps in the animation call tween twice (it suspends)
m
@Max Can you try adding the import
Copy code
import com.soywiz.korge.tween.get
m
importing that seems to solve the compilation issue! thanks!
👍 1
also, @jeff according to the documentation it looks like it supports two values. Start and end: https://korlibs.soywiz.com/korge/reference/animation/
n
fwiw the documentation does say you need to add that import. I have noticed that IntelliJ seems reluctant to automatically do it for you, which is kinda weird.
😊 1
d
I usually use star imports independently on the number of symbols you are importing. That way when importing the tween, it also imports the operator
get
overloads
message has been deleted
m
Thanks for all the help. Sorry i didn't see that mention of the import in the documentation.