Jump to content

Events linger after remove and destroy


MichaelD
 Share

Recommended Posts

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 this

text.inputEnabled = true;text.events.onInputDown.add(fn, this);

Thanks!

Link to comment
Share on other sites

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

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

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

  • 3 weeks later...

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

 Share

  • Recently Browsing   0 members

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