Elgan Posted June 16, 2014 Share Posted June 16, 2014 How can i turn off, remove physics for an object ie. my sprite must collide, then i can pick it up and carry it, but when carrying its physics get in the way . i have tried sprite.body.destroy() but it causes a crash...bug? Link to comment Share on other sites More sharing options...
lewster32 Posted June 16, 2014 Share Posted June 16, 2014 Do sprite.body.moves = false to stop physics acting upon the object while you manipulate it manually. Link to comment Share on other sites More sharing options...
Elgan Posted June 16, 2014 Author Share Posted June 16, 2014 thanx. I already have body.moves =false; Ill look into it. Is there also another way, if i would like to remove it's collision events? (thinking walking over items) Link to comment Share on other sites More sharing options...
lewster32 Posted June 16, 2014 Share Posted June 16, 2014 If you use the dev version, you can use body.enable = false to completely disable the body. This is not available on any version except dev at the moment. A way around this in the mean time is to check the body.moves property within your collision processCallback, something like so:game.physics.arcade.collide(player, enemies, function(player, enemy) { // ... collision code ...}, function(player, enemy) { // if this returns false, then the collision is ignored, so return the value // of player.body.moves to make non-moving sprites also ignore collision return player.body.moves;}); Link to comment Share on other sites More sharing options...
Elgan Posted June 16, 2014 Author Share Posted June 16, 2014 thanx, just what i wanted.I will try out the dev version; a combination of moves;enabled is perfect. also a note ....sprite.body.destroy() still crashes...This cant be right. Link to comment Share on other sites More sharing options...
lewster32 Posted June 16, 2014 Share Posted June 16, 2014 I don't think the body is meant to be destroyed unless the sprite is also destroyed cleanly, as there will still be routines running which are looking for methods and properties on the now missing body property. Does the same thing happen if you set the body to null? Can you paste in the error returned when it 'crashes'? Link to comment Share on other sites More sharing options...
Elgan Posted June 16, 2014 Author Share Posted June 16, 2014 sprite.body = null Does not crash, not sure on the body state, but it runs fine. sprite.body.desstroy() Uncaught TypeError: Cannot read property 'scale' of null */ updateBounds: function () { var asx = Math.abs(this.sprite.scale.x); var asy = Math.abs(this.sprite.scale.y);Sprite is null,hm.. Link to comment Share on other sites More sharing options...
lewster32 Posted June 16, 2014 Share Posted June 16, 2014 Looking into it, the problem is that destroy() sets the body's reference to the sprite (body.sprite) to null - but then other stuff still running on body does not check to make sure sprite is not null (a fair assumption in most cases) before accessing properties. Link to comment Share on other sites More sharing options...
j0hnskot Posted June 16, 2014 Share Posted June 16, 2014 destroying the body and then setting it to null doesn't give an error. Link to comment Share on other sites More sharing options...
lewster32 Posted June 16, 2014 Share Posted June 16, 2014 Given the code involved in body.destroy(), nulling the body will do all the same things as destroy plus more, in that it will release all of the body's contents from the sprite to the garbage collector. Link to comment Share on other sites More sharing options...
Recommended Posts