MichaelD Posted April 14, 2015 Share Posted April 14, 2015 Hello, I noticed that events attached on bitmapText objects tend to linger/persist even after the item has been removed/destroyed from the group or even after the group has been destroyed. Does anyone have any idea why is this happening? or how to solve this? I'm attaching the event like thistext.inputEnabled = true;text.events.onInputDown.add(fn, this);Thanks! Link to comment Share on other sites More sharing options...
Neso Posted April 21, 2015 Share Posted April 21, 2015 I had similar issue once though it was not with events. Maybe you are not destroying object but just removing reference to it. ANd since you passed the object in add function it will stay alive as garbage collector will not pick it up until all references are removed. And even then you cannot be certain when will garbage collector kick in. So my best bet is that you show how you remove items. Because I am certain event persists due to reference you passed. Link to comment Share on other sites More sharing options...
MichaelD Posted April 21, 2015 Author Share Posted April 21, 2015 I'm removing the children of the group they are in.group.removeChildren();I thought that would be sufficient to remove the listeners What works is running the following before I remove the children of the group:group.forEachExists(function (item) { item.getChildAt(0).events.onInputDown.removeAll();});But it seems a bit of an overkill for a simple task. Link to comment Share on other sites More sharing options...
stauzs Posted April 22, 2015 Share Posted April 22, 2015 // use to remove and destroy children // https://phaser.io/docs/2.3.0/Phaser.Group.html#removeAll group.removeAll(true); // use to just remove // https://phaser.io/docs/2.3.0/Phaser.Group.html#removeChildren group.removeChildren(); // won't call destroy on children - removes references Link to comment Share on other sites More sharing options...
MichaelD Posted April 22, 2015 Author Share Posted April 22, 2015 I have also tried using removeAll(true) but it seems that if I try to removeAll and then try to add it throws an error Uncaught TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)'If I do the insertion asynchronously it plays fine, I wonder if the removeAll is set to run async and thus it is still removing while I try to add stuff to the group. Other than than the removeAll works fine. Link to comment Share on other sites More sharing options...
fariazz Posted May 8, 2015 Share Posted May 8, 2015 I have the same issue and found another workaround: Before loading the new state (in my case it was actually reloading the current one), manually remove the tileSprites from your game world, only then launch the new state. This worked for me:gameOver: function(){ //my two tileSprites this.game.world.remove(this.background); this.game.world.remove(this.water); this.game.state.start('Game'); } Link to comment Share on other sites More sharing options...
Recommended Posts