Jump to content

creating player with extended class creates two images


Recommended Posts


I am creating my player with an extended Sprite class

export default class playerDefault extends Phaser.GameObjects.Sprite {
    constructor(scene, x, y) {
        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?


Screenshot from 2021-11-25 14-32-13.png

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...