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

jeff

01/18/2021, 1:53 AM
Conflicting calls to
tween
cause an ugly flicker. Is there a better way to avoid that than manually tracking Jobs? Example in 🧵
Copy code
class TestScene : Scene() {
    override suspend fun Container.sceneInit() {
        val redBox = solidRect(100, 100, Colors.RED) {
            xy(0, 0)
        }
        launch {
            val firstJob = launch { redBox.tween(redBox::x[500], time = 3.seconds) }
            delay(1500)
            // firstJob.cancel() <-- this fixes the issue but is cumbersome
            // at t=3000 when the first tween finishes, box jumps to 500, but then resumes its animation towards 0
            launch { redBox.tween(redBox::x[0], time = 3.seconds) }
        }
    }
}
Ideally it would be great if tweens to a matching
V2
cancelled prior calls. I don't know how feasible that is.
m

Mayank

01/18/2021, 7:50 AM
Sorry if I didn’t understand the question but why not change the time of first tween to 1.5 seconds? You can also simply remove inner launch statements and do something like
Copy code
launch {
    redBox.tween(redBox::x[500], time = 1.5.seconds)
    redBox.tween(redBox::x[0], time = 3.seconds)
}
d

Deactivated User

01/18/2021, 11:21 AM
I think the animation API handles those situations (cancellating previous stuff by finalizing the animation or keeping the current properties). But have to check to be sure
j

jeff

01/18/2021, 3:12 PM
Yeah this was a contrived example. This happens for example if I have a view that animates up or down when clicked, if you click it twice before the animation completes
I looked through tween's source code and didn't see anything checking for a pre-existing TweenComponent, but I'm no expert.
That's not a tween but something different
j

jeff

01/18/2021, 6:40 PM
Ah, gotcha. I'll check that out, thanks!
👍 1
8 Views