Not being able to add texture

am trying to build a ES6 class to modularize my project. I had this working file:

player = this.physics.add.sprite(200, 200, ‘player’);

And so far I was able to replace it on create() like this:

player = new Sprite(this, 200, 200, ‘player’);

With the sprite class being:

class Sprite extends Phaser.Physics.Arcade.Sprite {

constructor(scene, xIni, yIni, img) {

    super(scene, xIni, yIni, img);

    scene.physics.add.existing(this);

}

}

Everything is working fine(collisions, intersections, etc.), however the texture is not appearing. It’s sort of transparent, I can move the object, but the image doesn’t appear.

I have already tried to add this.setTexture(‘player’); on the constructor, however it didn’t work either.

I preload my player like this in the preload() function: this.load.atlas(‘player’, ‘/Resources/player.png’, ‘/Resources/player.json’);

Thank you

I guess it should be

class Sprite extends Phaser.Physics.Arcade.Sprite {
  constructor(scene, xIni, yIni, img) {
    super(scene, xIni, yIni, img)
    scene.add.existing(this)
    scene.physics.add.existing(this)
  }
}

Hi @amserra,
I also had the same problem extending the class Phaser.Physics.Arcade.Image and my solution was to add the new object from the scene:

// In your create() function
player = this.add.existing(new Sprite(this, 200, 200, 'player'));

// In your constructor
scene.physics.world.enable(this);

Warning: you couldn’t manipulate the body from the constructor of your Sprite class, since at that moment it still haven’t it.
Regards.

Thank you!!