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

Global sprites


Raiper34
 Share

Recommended Posts

Hi, 

 

I created global sprite in state this way 

player = this.add(...)

When i go to another state, is it costuming memory or not? What if i change it to game.add(...) is this in memory, even if there is not sprite on the screen? It is maybe not problem about phaser, but canvas but i want to know it and i do not know how this problem google it, maybe you do not understand me too... 

 

Thanks.

Link to comment
Share on other sites

Couldn't the question be more like this? Does Phaser remove references to it's objects stored in global variables when transiting from one state to another? Otherwise your question doesn't make much sense to me.

 

Some pseudo-code as I imagine the situation:

var player;var state1 = function() {};state1.prototype = {  create: function() {    player = this.add.sprite(x, y, 'player');    this.state.start('state2');  }};var state2 = function() {};state2.prototype = {  create: function() {    // there is no player in this state needed so is player still kept in memory or does Phaser removes it's reference or does GC understands it can remove it?  }};

I don't know about Phaser but my guess would be that you need to take care of your global reference yourself. If you want you can easily test it, create your global var, store a sprite in it, transt states, stop the game and outside of phaser functions check your global var if it's still there or not is your answer, isn't it?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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