You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This manifests itself when adding game objects to the display list through scene.children.add. If a game object has already been added to the scene's display list, and it is added again as a part of an array using scene.children.add, it can prevent valid game objects from being added.
The expected behavior here is to see all three text objects. The actual result is text1 being added twice and text2 being added once, while text3 is not added at all.
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.
Version
Phaser Version: 3.15.1
Description
Phaser.Utils.Array.Add
's behavior is incorrect when adding elements to an array in which they already exist.Example:
This manifests itself when adding game objects to the display list through
scene.children.add
. If a game object has already been added to the scene's display list, and it is added again as a part of an array usingscene.children.add
, it can prevent valid game objects from being added.Example Test Code
Direct example
Game object example
The expected behavior here is to see all three text objects. The actual result is
text1
being added twice andtext2
being added once, whiletext3
is not added at all.Additional Information
The problematic code is here: https://github.com/photonstorm/phaser/blob/04080bc1bab46834e4e9947a17905c1be0d5560b/src/utils/array/Add.js#L75
A quick fix is to replace
item.pop();
withitem.splice(itemLength, 1);
.item.pop();
is incorrect because the duplicate item is not always in the last position of the array!The text was updated successfully, but these errors were encountered: