tembac Posted September 9, 2016 Share Posted September 9, 2016 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 More sharing options...
samme Posted September 9, 2016 Share Posted September 9, 2016 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 More sharing options...
tembac Posted September 9, 2016 Author Share Posted September 9, 2016 Ah, thanks! Didn't know this. So if I reset the sprite the same body is used? Link to comment Share on other sites More sharing options...
samme Posted September 9, 2016 Share Posted September 9, 2016 Yes, it's the same body, but it gets reset too, so there should be no carryover. tembac 1 Link to comment Share on other sites More sharing options...
samme Posted September 9, 2016 Share Posted September 9, 2016 47 minutes ago, tembac said: If I render the body I can still see it: I was perplexed by this too at first. tembac 1 Link to comment Share on other sites More sharing options...
Recommended Posts