# Creating player with extended class creates dubble sprites

**URL:** <https://phaser.discourse.group/t/creating-player-with-extended-class-creates-dubble-sprites/10755>\
**Category:** Phaser 3\
**Created:** [November 27, 2021, 12:25am UTC](https://phaser.discourse.group/t/creating-player-with-extended-class-creates-dubble-sprites/10755 "2021-11-27T00:25:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrmaarten](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/mrmaarten/32/5905_2.png) [@mrmaarten](https://phaser.discourse.group/u/mrmaarten)\
**Post date:** [November 27, 2021, 12:25am UTC](https://phaser.discourse.group/t/creating-player-with-extended-class-creates-dubble-sprites/10755/1 "2021-11-27T00:25:17Z")

</div>

Hi!

I am creating my player with an extended Sprite class

```javascript
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!

---

<div class="post-metadata">

**Author:** ![REALziez](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/realziez/32/5897_2.png) [@REALziez](https://phaser.discourse.group/u/REALziez)\
**Post date:** [November 27, 2021, 12:40am UTC](https://phaser.discourse.group/t/creating-player-with-extended-class-creates-dubble-sprites/10755/2 "2021-11-27T00:40:15Z")

</div>

I’m pretty sure you are creating 2 sprites. If you send me more of your code I might be able to help you fix it.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [November 27, 2021, 1:00am UTC](https://phaser.discourse.group/t/creating-player-with-extended-class-creates-dubble-sprites/10755/3 "2021-11-27T01:00:03Z")

</div>

```javascript
class playerDefault extends Phaser.GameObjects.Sprite {
  constructor(scene, x, y, texture) {
    super(scene, x, y, texture);

    this.scene.add.existing(this);
    this.scene.physics.add.existing(this);

    this.body.onOverlap = true;
  }
}

```

```javascript
// In scene:
this.player = new playerDefault(this, 100, 100, 'texture');

```

`new playerDefault(…)` **is** the sprite. It shouldn’t call `physics.add.sprite(…)`, which would add a second sprite.

---

<div class="post-metadata">

**Author:** ![mrmaarten](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/mrmaarten/32/5905_2.png) [@mrmaarten](https://phaser.discourse.group/u/mrmaarten)\
**Post date:** [November 29, 2021, 10:11am UTC](https://phaser.discourse.group/t/creating-player-with-extended-class-creates-dubble-sprites/10755/4 "2021-11-29T10:11:17Z")

</div>

Ah yes, I see. That is the explanation. Thanks!
