Help with extending a group

Hey folks, newbie programmer here. I have some experience with phaser 2, but i’ve hit a wall with phaser 3 and extending a group.

My code looks like this for the group itself

class Enemies extends Phaser.Physics.Arcade.Group {
constructor(world, scene, config) {
super(world, scene, config);

//none of the 3 below help :confused: 
/*
scene.add.existing(this);
scene.physics.add.existing(this);
scene.physics.world.enableBody(this, 0);
*/

}

and here i use new to create the group and create an enemy

_initEnemies(){
this.enemies = new Enemies(this, this);
this.sprite = this.enemies.create(100, 100, ‘playerSprites’);
}

but the enemy is not created. Nothing happens. I’ve googled left and right and found nothing. I’m also wondering if its possible to create the enemy from within the extended sprite class?

Thanks for your time :smiley:

class Enemies extends Phaser.Physics.Arcade.Group {}

function create () {
  var group = this.add.existing(
    new Enemies(
      this.physics.world,
      this,
      {}
    ));
}
1 Like

Thank you very much Samme, sorry to ask another question as i feel im missing something obvious.

When i use group.create on my physics group, like so

this.enemy = this.enemies.create({
x: 100,
y: 100,
key: ‘enemySprites’,
frame: 0,
active: true,
visible: true
});

Nothing happens?

this.enemy = this.enemies.create(100, 100, ‘enemySprites’);

The above does not work either

EDIT: this.enemy returns undefined

EDIT: Nevermind im an idiot, thanks for the help Samme