Reputation: 89
I used to handle a group of sprites by push them into an array or sprite group which is build-in class in the Phaser. But I am seeking another simple way could get or remove all sprites in an scene. Does anyone have any idea to resolve this? Thanks a lot!
Upvotes: 2
Views: 1505
Reputation: 14760
The Scene has a property children
(link to documentation)
You can get all Sprites, with the command:
// where this = the current scene
let allSprites = this.children.list.filter(x => x instanceof Phaser.GameObjects.Sprite);
And then remove/destroy them all, like this:
allSprites.forEach(x => x.destroy());
Just iterating through the list of sprites, and calling the destroy
function on each object.
Upvotes: 2