Jump to content

Disable / remove phusics?


Elgan
 Share

Recommended Posts

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

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

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

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

 Share

  • Recently Browsing   0 members

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