tproper Posted October 19, 2018 Share Posted October 19, 2018 So, say I have this: var some_objects = [] function create() { for(var i = 0; i < 10; i++){ var graphics = game.add.graphics(0,0); graphics.beginFill(color, 1); graphics.drawCircle(0, 0, 50); some_objects.push(graphics); } } function kill(){ some_objects.forEach(obj => { obj.destroy(); }); } Is this a good way to clean up/remove everything? The some_objects is still an array of 'somethings'. Do I need to also do something like this: some_objects = [] Or is leaving some_objects an array, of what I think is empty references, okay to do? I'm asking this because I don't want the game to slow down after a while because I'm not cleaning up my instances/objects/variables/whatever. Link to comment Share on other sites More sharing options...
samme Posted October 19, 2018 Share Posted October 19, 2018 That's fine. You can also do some_objects.length = 0; You can also use a Group, which has built-in methods for a lot of these things. Link to comment Share on other sites More sharing options...
tproper Posted October 22, 2018 Author Share Posted October 22, 2018 OK. I'll look into Groups. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts