phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.17k stars 7.1k forks source link

Tweens: Duration of 0 Makes Values NaN (Alpha) #6955

Open kainage opened 12 hours ago

kainage commented 12 hours ago

Version

Description

Adding a tween with a duration of 0 leaves the object in an invalid state with NaN as the value and cannot be tweened afterwards, unless the value is explicitly set to a valid one.

NOTE: This works in 3.86.0 and prior

Example Test Code

Tweak the sprite alpha example to a tween and see the outcome. This might be happening with other values, but I haven't tested those.

Sandbox

class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v385');
        this.load.image('bunny', 'assets/sprites/bunny.png');
    }

    create ()
    {
        const bunny = this.add.sprite(400, 300, 'bunny');

        this.add.tween(
            {
                targets: bunny,
                alpha: 0.5,
                duration: 0
            }
        )

        console.log(bunny)
    }
}

const config = {
    type: Phaser.WEBGL,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    scene: Example
};

const game = new Phaser.Game(config);
photonstorm commented 5 hours ago

What's the point of a duration of zero?