Chupup Games Posted March 14, 2014 Share Posted March 14, 2014 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 More sharing options...
Heppell08 Posted March 14, 2014 Share Posted March 14, 2014 Is it not possibly because you called it this.dude? Maybe it might need to be this.this.dude.destroy(); because the namespace you given already includes this. Link to comment Share on other sites More sharing options...
Natman Posted March 14, 2014 Share Posted March 14, 2014 I'm pretty sure you should be usingthis.dude.kill();instead ofthis.dude.destroy();I'm not 100% sure because I'm very new to Phaser, but this is the way it was described in the Making Your First Game tutorial. I think that will fix your problem. Link to comment Share on other sites More sharing options...
Chupup Games Posted March 15, 2014 Author Share Posted March 15, 2014 @Natman in the API it says that kill() don't frees up the memory, it only makes the sprite invisible..anyway, destroy() should work @Heppell08 i will give it a try, but i never see this.this before Link to comment Share on other sites More sharing options...
Chupup Games Posted March 15, 2014 Author Share Posted March 15, 2014 The kill method works, but i am still curious why destroy doesn't want to work... Link to comment Share on other sites More sharing options...
rich Posted March 15, 2014 Share Posted March 15, 2014 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. stevenb 1 Link to comment Share on other sites More sharing options...
Chupup Games Posted March 15, 2014 Author Share Posted March 15, 2014 ok, this works! Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts