Hey there,
I have two sprites in a Container.
Both sprites are created differently and i’m wondering why they both do not function the same:
let animationSprite_1 = new Phaser.GameObjects.Sprite(scene, 0, 0);
animationSprite_1.play("walk");
this.add(animationSprite_1);
let animationSprite_2 = scene.add.sprite(0, 0);
animationSprite_2.play("walk");
this.add(animationSprite_2);
animationSprite_1 -> Animation NOT playing
animationSprite_2 -> Animation playing as expected
I know that most people use the scene.add.sprite() syntax but Phaser offers to use the new Class() syntax as well … is there a difference between the two or am i doing something wrong?
For the first sprite, you can add the existing game object to the same with add.existing(). This should add the object to the scene’s update list. Example:
scene.add.existing did the job.
Still i’m wondering why i could already see the sprite. In my understanding i should not be able to see a sprite when it is not in the scene’s updatelist.
Since i pass scene into new Sprite() it should either exist only in the memory and not visible or if it is visible it should automatically be added to the updatelist.
However - thanks a lot for your time!