Hello everyone,
I’m trying to create a life system. When the character touch an bomb we removed one life (represented by a hearth) I’ve already create objects but I can’t delete one object.
lives = this.physics.add.staticGroup();
lives.create(300, 35, ‘hearth’);
lives.create(350, 35, ‘hearth’);
lives.create(400, 35, ‘hearth’);
//then character touch a bom
I try this but 2 hearth was removed
lives.getChildren().map(child => child.destroy())
Anyone can tell me where I’m I was wrong please?
Regards
Hi @remi-boivin,
If you want to remove only one item from the group. You can use something like this:
lives.remove(lives.getLast(true), true);
I don’t know why your code does not delete all the elements of the group, but only 2. The map function should iterate all elements and return a new array.
Maybe I’m wrong, but if you are using hearts for the ui, you don’t need a physics group.
Regards.