Raiper34 Posted August 6, 2015 Share Posted August 6, 2015 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 More sharing options...
Raiper34 Posted August 6, 2015 Author Share Posted August 6, 2015 Or better, is it still in memory? Shoudl I destroy it manually? Link to comment Share on other sites More sharing options...
drhayes Posted August 7, 2015 Share Posted August 7, 2015 I'm not quite sure what you're asking? It sounds like you're asking if it consumes too much memory to keep sprites around between state transitions? I wouldn't worry about that too much. Link to comment Share on other sites More sharing options...
AzraelTycka Posted August 7, 2015 Share Posted August 7, 2015 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 More sharing options...
Raiper34 Posted August 8, 2015 Author Share Posted August 8, 2015 Hmmm but is this global sprite only stop redner, or it is destory? This is maybe right question. Link to comment Share on other sites More sharing options...
AzraelTycka Posted August 8, 2015 Share Posted August 8, 2015 Well if it's destroyed then GC takes care of it, so my suggestion above should give you an answer. If it's rendered or not should be obviously simple to test the same way, so both your answers are waiting for you until you test it. Link to comment Share on other sites More sharing options...
Recommended Posts