Jump to content

Getting width and height from body


lonelydatum
 Share

Recommended Posts

Hi there,

 

I'm trying to get the width and height from the returned body:

var body = this.game.physics.p2.convertCollisionObjects(map, "floorMiddle")[0];

 

It would be great if this was possible: 

body.width

body.height

 

And, unfortunately the body.sprite=null otherwise I'd just access the sprite info.

 

Thanks,
Gar

Link to comment
Share on other sites

You could try working it out from body.data.aabb.lowerBound and body.data.aabb.upperBound 

 

 

edit:

 

 

body.width = this.physics.p2.mpx(body.data.aabb.upperBound[0] - body.data.aabb.lowerBound[0]);body.height = this.physics.p2.mpx(body.data.aabb.upperBound[1] - body.data.aabb.lowerBound[1]);
Link to comment
Share on other sites

@wayfinder, thanks for pointing me in the right direction! :)

 

I first needed to update the aabb Float32Array: body.data.aabb.updateAABB();

var width = this.game.physics.p2.mpx(body.data.aabb.upperBound[0] - body.data.aabb.lowerBound[0]);

var height = this.game.physics.p2.mpx(body.data.aabb.upperBound[1] - body.data.aabb.lowerBound[1]);

 

Otherwise the upperbounds/lowerbounds were always equal to zero.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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