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

Max

12/16/2020, 9:04 AM
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

Deactivated User

12/16/2020, 11:22 AM
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

Max

12/16/2020, 11:28 AM
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

Deactivated User

12/16/2020, 11:38 AM
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

Max

12/16/2020, 11:48 AM
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

jeff

12/16/2020, 2:58 PM
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

Mayank

12/16/2020, 4:03 PM
@Max Can you try adding the import
Copy code
import com.soywiz.korge.tween.get
m

Max

12/16/2020, 4:25 PM
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

nanodeath

12/16/2020, 5:30 PM
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

Deactivated User

12/16/2020, 5:36 PM
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

Max

12/18/2020, 8:43 AM
Thanks for all the help. Sorry i didn't see that mention of the import in the documentation.
6 Views