How do you reuse a tween that has finished playing with different end values

Hi,
I’ve been testing the updatTo() function to reset a tween, but it doesn’t work if the tween already finished. How do you do it when that’s the case?

Here’s a simplified example of what I’m trying to do:


var nextAngleChangeTime = 3000;
var curAngle = 0;

//...

function create(){
    //...
    direction = { angle: curAngle };
    directionTween = scn.tweens.add({
        targets: dirObj,
        angle: curAngle,
        duration: 2000,
        repeat: 0,
    });

}

function update(time, delta) {
    if (time > nextAngleChangeTime) {
        nextAngleChangeTime = time + 3000;
        curAngle += Math.PI/2 - Math.random()*Math.PI;

        directionTween.updateTo('angle', curAngle, true);
        directionTween.restart();
    }
    //...
}

The currAngle value changed every 3 seconds, but the direction.angle remained as at the end of the first 2 seconds tween. Don’t know whether this is a bug or I’m getting it wrong.

I tried something different as a workaround and for this simplified case it works:

function update(time, delta) {
    if (time > nextAngleChangeTime) {
        nextAngleChangeTime = time + 3000;
        curAngle += Math.PI/2 - Math.random()*Math.PI;

        //directionTween.updateTo('angle', curAngle, true);
        directionTween.restart();
        console.log('New target Angle:', curAngle);
    }
    if(curAngle !== direction.angle) {
        directionTween.updateTo('angle', curAngle, true);
    }
    console.log('tweened angle:', direction.angle);
    //...
}

But the problem is that if the angle gets changed outside of this controlled situation (which I need for several reasons), managing the situation with this workaround gets really awkward.

Any idea on how could I reuse this tween in any way different?