Jump to content

Destroying a sprite that has events?


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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