coolmitch Posted November 12, 2014 Share Posted November 12, 2014 Haven't been able to find anything in search-- apologies if this has been covered before. In my game, I have a "players" object that's stored on the Phaser game object for convenience (i need these properties across several states). The players object holds data about each player in the game, one of those properties being a reference to a sprite (part of the game involves customizing your own character sprite, including attaching child sprites) It works great, except that I'm having trouble transfering sprites that have already been added to the game world in one state, to another state. I am aware that I can keep sprites around by not clearning the world on state transition, but since there are many sprites I want to clear and only a few I want to keep, this seems inefficient. Here's a codepen showing the problem. Check out the console: Phaser throws "TypeError: this._bindings is undefined" when the this.game.add.existing line executes. http://codepen.io/anon/pen/jEONap What am I missing? Thanks! Link to comment Share on other sites More sharing options...
lewster32 Posted November 12, 2014 Share Posted November 12, 2014 Because ending a state destroys the whole display list recursively, you can save any sprites from this process by removing them from the display list in the shutdown function of the ending state: http://codepen.io/lewster32/pen/XJWJde Alternatively, you could extend the standard Sprite object to have different functionality for its destroy method so that by default those objects are not blitzed. Link to comment Share on other sites More sharing options...
coolmitch Posted November 12, 2014 Author Share Posted November 12, 2014 Beautiful. Thanks a lot. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts