How to delete a line segment in phaser 3?

Viewed 444

I have created multiple lines in Phaser 3 and now need to remove them. I am mainly searching for a way to delete them entirely instead of just making them invisible. The code I have used to create the lines is below:

graphics = game.add.graphics({ lineStyle: {width: 4, color: 0xa9a9a9 } });
line = new Phaser.Geom.Line(100, 100, 200, 200)
graphics.strokeLineShape(line)

Thanks

1 Answers

you're looking for .destroy()


graphics = game.add.graphics({ lineStyle: {width: 4, color: 0xa9a9a9 } });
line = new Phaser.Geom.Line(100, 100, 200, 200)
graphics.strokeLineShape(line)

if(//do something) {
    graphics.destroy();
}

This will completely destroy the asset from the game. there is no undestroy method so you will have to call a new line to spawn it. :)

Hope this helps!

Related