Jump to content

Body is not killed when extending sprite


tembac
 Share

Recommended Posts

Hi everyone,

I'm extending an sprite with the following code:


Monster = function (game, x, y) {

  Phaser.Sprite.call(this, game, x, y, 'monster01');

  this.game.physics.enable(this, Phaser.Physics.ARCADE);

  //graphics
  this.anchor.set(.5, 1);

  this.body.setSize(290, 670, 330, 110);
};

Monster.prototype = Object.create(Phaser.Sprite.prototype);
Monster.prototype.constructor = Monster;

Monster.prototype.update = function()
{
  //input
  if(this.game.input.activePointer.isDown)
  {
    if(Phaser.Rectangle.contains(this.body, this.game.input.worldX, this.game.input.worldY))
    {
      BasicGame.PPGPlayer.clickOnMonster(this);
    }
  }
};

I'm adding this sprite to the main state using:

this.monster = new Monster(this.game, this.game.world.width * .5 + 400, 990);
this.add.existing(this.monster);

Then, I'm killing it with this.monster.kill() and the sprite disappears but the body is still on the state. If I render the body I can still see it:

  render: function (){
		this.game.debug.body(this.monster);
  },

 


Why is this happening and what is the best way to solve it?

Thanks!

 

Link to comment
Share on other sites

31 minutes ago, tembac said:

Then, I'm killing it with this.monster.kill() and the sprite disappears but the body is still on the state. If I render the body I can still see it:

This is actually normal for sprites with Arcade Physics bodies. When a sprite dies, the body isn't removed or disabled, but it ceases being updated (moved) and is excluded from collision checks, so it shouldn't interact with anything. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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