Jump to content

Destroy a sprite


Chupup Games
 Share

Recommended Posts

i have a sprite, that i want to destroy when the player touches it,

but i get this error:

 

Uncaught TypeError: Object [object Object] has no method 'destroy'

this.dude = game.add.sprite(Math.floor(Math.random() * 480 + 100), -50, 'tiles');            this.dude.animations.add('float', [animFrame, animFrame + 1], 10, true);            this.dude.animations.play('float');            game.physics.enable(this.dude, Phaser.Physics.ARCADE);            this.dude.body.velocity.x = -50;            this.dude.body.velocity.y = 30;            this.dudeDead = false;                            if (this.dude.body.y > 320) {                this.dudeDead = true;                this.dude.destroy();
Link to comment
Share on other sites

Actually it's a bug, sorry. It's fixed in the dev branch, but for now do this:

 

this.dude.body = null;

this.dude.destroy();

 

Basically it's trying to destroy the Arcade Physics Body, which doesn't have a destroy method, hence the error. Nulling the body first will stop it from trying to destroy it.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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