Hi!
I am creating my player with an extended Sprite class
export default class playerDefault extends Phaser.GameObjects.Sprite {
constructor(scene, x, y) {
super(scene)
this.scene = scene;
// this.scene.add.existing(this)
// this.scene.physics.add.existing(this)
this.x = x;
this.y = y;
this.player = this.scene.player
this.playerAvatarPlaceholder = this.scene.playerAvatarPlaceholder
this.player = this.scene.physics.add
.sprite(this.x, this.y, this.playerAvatarPlaceholder)
this.player.body.onOverlap = true
}
}
I create my player in the game scene with:
this.player = this.physics.add.existing(new playerDefault(this, 100, 100))
It works, it creates a player that moves, but there is a second sprite created, that appears when the player moves.
Adding .setVisible(false) to the class, hides this second sprite, but I find it strange that it is created in the first place, especially by the class.
Anybody idea’s why this is happening?
Thanks!