Search the Community
Showing results for tags 'persistence'.
-
I am trying to test out persistence of objects--at the moment an image, but eventually a group that will be a UI component. Right now, my image that I want to persist ("persist") goes from State1 to State2 just fine, but when I go back to State1, it disappears and I get an error ("uncaught typeError: cannot read property 'compressionAlgorithm of null in Phaser.js" and then points to a bunch of pixi.webgl render locations) Why is the item disappearing if it's been added to the stage, and how do I overcome this problem? Here is the code for State1: var state1 = { preload: function () { this.load.image('persist', 'persist.png'); this.load.image('btn', 'btn.png'); }, create: function () { this.persist = game.add.image(this.world.centerX, this.world.centerY, 'persist'); this.game.stage.addChild(this.persist); this.btn = this.add.image(200, 200, 'btn'); this.btn.inputEnabled = true; this.btn.events.onInputDown.add(this.changeState, this); }, changeState: function() { this.state.start("state2"); } And then State 2 is just taking us back to state1 on clicking the button var state2 ={ preload: function(){ this.load.image('btn', 'inventory/btn.png'); }, create: function(){ this.btn = this.add.image(200, 200, 'btn'); this.btn.inputEnabled = true; this.btn.events.onInputDown.add(this.changeState, this); }, changeState: function(){ this.state.start("state1"); } }; Thanks in advance