In Phaser, is there a way to clear the screen or clear the game stage / world?

I'm looking for an easy and quick way to clear the entire Phaser screen, for example how in HTML5 canvas you can erase everything by resetting the entire canvas width. I couldn't find any such method with the graphics.clear () search engine, but it doesn't touch on other things like text objects. Is there a way to clear the screen?

Thank.

+3


source to share


2 answers


There are methods for destroying certain elements - obj.kill()

and obj.destroy()

- but you can delete all elements by calling game.world.removeAll()

.



+4


source


@ FabiánRodríguez answered, but you can also make an array or object literal with the objects you want to delete in order to iterate and delete them. That is when you want to group objects.



var layout = {
    rect: new Phaser.Rectangle(0, 0, 200, 200)
};

for(var i in layout) {
    layout[i].kill();
    layout[i].remove();
}

      

0


source







All Articles