Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

What should be included in the shutdown method?


toto88x
 Share

Recommended Posts

Hello,

 

If I have something like this in my create function:

create: function () {    this.cursor = game.input.keyboard.createCursorKeys();    this.label = game.add.text(w/2, h/2, 'test', { fontSize: '34px', fill: '#fff' });    this.label.anchor.setTo(0.5, 0.5);    this.player = game.add.sprite(w/2, h/2, 'player');    this.player.body.collideWorldBounds = true;    this.enemies = game.add.group();    this.enemies.createMultiple(20, 'enemy');    this.enemies.setAll('outOfBoundsKill', true);    this.hit_s = game.add.audio('hit');    this.score = 0;}

What should be included in the shutdown method to clean up all the memory? And how to do it?

 

Thanks!

Link to comment
Share on other sites

I'm in the habit of explicitly destroying everything that can be destroyed.

shutdown: function () {    this.cursor = null;    this.label = null;    if (this.player) {        this.player.destroy();        this.player = null;    }    if (this.enemies) {        this.enemies.destroy(true);        this.enemies = null;    }        if (this.hit_s) {        this.hit_s.stop();        this.hit_s = null;    }}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...