Passing in a Public Variable into a Tween

So I have recently been learning cc.tween in Cocos Creator, and they have been easy to use, and work great overall. One issue I’ve ran into is I can’t seem to find a way to adjust them on the fly in the editor. For example, say I have a tween where one line of code is, .to(5, {rotation: 1080}, {easing: ‘quadOut’}), and it works as expected. The object rotates three times over five seconds. What I can’t do is something like this, .to(timer, {spins * 360}, {easing: ‘quadOut’}), where you can control the time and the amount of spins in the editor as much as you need, instead of going in and changing the code each time.

I am going through some documentation, and it’s possible I’ve missed it, so any help would be greatly appreciated.

Hey, it seems to be working with variables on my end. Perhaps you need to rectify your code:

.to(timer, {rotation: spins * 360}, {easing: ‘quadOut’})

cc.tween(this.flipper)
.tag(0)
.set({angle: this.rotationSpreadInDegrees})
.repeatForever(
cc.tween()
.to(this.rotationDuration, { angle: -this.rotationSpreadInDegrees })
.delay(this.delayBetweenRotation)
.to(this.rotationDuration, { angle: this.rotationSpreadInDegrees })
.delay(this.delayBetweenRotation)
)
.start();

1 Like

Yep, that indeed works! I just forgot to type ‘this.’ before my variables. Thank you very much for your help.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.