phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Calling updateTo on tween doesn't update it's end/start value

Open MartinEyebab opened this issue 2 years ago • 2 comments

Version

  • Phaser Version: Phaser v3.60.0 Beta 4
  • Operating system: Windows 10

Description

The docs for Tween.updateTo() say "Updates the 'end' value of the given property across all matching targets." and "You can optionally tell it to set the 'start' value to be the current value (before the change)." However as demonstrated by the standalone test case below, calling Tween.updateTo() doesn't actually update the end or start value of the Tween.

Example Test Code

var config = {
    type: Phaser.WEBGL,
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var arrow;
var tween;
var text;

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('arrow', 'assets/sprites/arrow.png');
}

function create ()
{
    text = this.add.text(30, 20, '0', { font: '16px Courier', fill: '#00ff00' });

    arrow = this.add.image(400, 300, 'arrow');

    tween = this.tweens.add({
        targets: arrow,
        x: 600,
        y: 300,
        ease: 'Sine.easeIn',
        duration: 2000,
        paused: true
    });

    this.input.on('pointerdown', function () {


        tween.updateTo('x', this.input.x, true);
        tween.updateTo('y', this.input.y, true);

        tween.play();

    },this);
}

function update ()
{
    arrow.rotation = Math.atan2(this.input.y - arrow.y, this.input.x - arrow.x);

    if (tween.isPlaying())
    {
        text.setText('Progress: ' + tween.progress);
    }
    else
    {
        text.setText('Click to start');
    }
}

Expected result: Arrow goes to the clicked spot when playing Actual result: Arrow goes to the spot designated in the config

Additional Information

Same result if you do it on a tween that has finished, and you want it to go somewhere else.

Tween.updateTo() works correctly if you set it in the update function

MartinEyebab avatar Feb 15 '22 09:02 MartinEyebab

The Tween has to be active and playing for updateTo to do anything. It cannot do anything on a Tween that has yet to start, or has completed.

photonstorm avatar Feb 19 '22 14:02 photonstorm

As it is, the docs makes it sound like it doesn't matter (it doesn't say anything about having it be active), but if it works as intended, then i'd suppose this would be a feature request, for a function to update the start/end properties of a tween

MartinEyebab avatar Feb 21 '22 07:02 MartinEyebab