Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing an array that was passed in as a tween target causes the objects to not tween (possibly intended) #7005

Open
Stever1388 opened this issue Jan 9, 2025 · 0 comments

Comments

@Stever1388
Copy link

Version

  • Phaser Version: 3.86.0
  • Operating system: Windows
  • Browser: Chrome

Description

If you pass in an array as the targets property for a tween config, and then change that array, specifically if you insert elements into the array, the whole array doesn't tween and any elements outside of the original length of the array won't get tweened.

Example Test Code

export default class ArrayTweenIssue extends Phaser.Scene {

  create() {
    this.add.circle(0,0,100, 0xff0000);
    this.add.rectangle(this.scale.width,0,100, 100, 0x00ff00);
    this.add.ellipse(0,this.scale.height,100, 100, 0x00ff00);
    this.add.star(this.scale.width,this.scale.height,5, 25, 100, 0x00ff00);

    this.tweens.add({ targets: this.children.list, duration: 1000, props: { x: this.scale.width / 2, y: this.scale.height / 2 } });

    // add another item afterwards
    const t = this.add.text(this.scale.width / 2, this.scale.height / 2, 'Test Text', { align: 'center' }).setOrigin(0.5);

    // move it so that it's within the original lists count
    this.children.moveTo(t, 1);
  }
}

In the example above, you would sort of expect the 4 shapes to tween towards the center, but the star doesn't. In Phaser 3.55.2, all of the shapes would still tween towards the center. If the text wasn't added at the center, it would get tweened towards the center (in both Phaser 3.55.2 and Phaser 3.86.0).

Additional Information

This use to work correctly in Phaser 3.55.2. This may be intended. My guess is that somewhere the length of the array is being stored so if the array length changes, the old array length is still used. However, it doesn't seem to affect if you remove an element from the array - such as destroying one of the gameobjects to cause this.children.list to be smaller than it originally was, I thought maybe would cause null reference errors but it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants