Jump to content

Destroying a sprite that has events?


agmcleod
 Share

Recommended Posts

I seem to be getting an error which I believe is related to the event handling. Inside an onInputDown, I call destroy on the said sprite to remove it from the game. However I instantly get the error: TypeError: this.sprite is null phaser.min.js:6

 

Running on chrome, I see:

 

Uncaught TypeError: Cannot read property 'events' of null

 

Not sure why I'm getting separate errors, but it seems to be related to events. Is there a proper way to cleanup events?

Link to comment
Share on other sites

After updating my bitmapfont objects, since it used the old API, it seems to work. Though I wonder if you have a suggestion for a better way to handle the following. This is my click handler on the sprite:

function() {    this.showDialogue = true;    keepsake.DialogueManager.show();    this.item.destroy();    this.item = null;    this.dialogues[0].stageBitmapText();  }

A Layer object is what's passed as "this", and it contians the said sprite, in this.item. I call destroy, but then in my function where i swap layers:

Layer.prototype.hide = function() {  this.music.stop();  if(this.item) {    this.item.kill();  }  this.background.kill();  keepsake.DialogueManager.hide();}

The this.item still validates, and it tries to kill the sprite, which fails due to me calling destroy on it earlier. So for now I set it to null in the first statement, but I'm wondering if there's a better way to handle its cleanup.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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