ZoomBox Posted April 4, 2014 Share Posted April 4, 2014 Hello ! I would like to know how can I get the bounds from a body ?I'm using Physics.P2 and I can't figure out how to get them. On top of that, I would like to get the Width and Height of a body (but coordinates would be nice too). Thank you in advance for your answers. Link to comment Share on other sites More sharing options...
Heppell08 Posted April 4, 2014 Share Posted April 4, 2014 Normally for the co-ords if I'm right in what you want then its:console.log('X:' + player.x);console.log('Y:' + player.y); Link to comment Share on other sites More sharing options...
JP91 Posted April 4, 2014 Share Posted April 4, 2014 by default every object is a rectangle, you can get the width with sprite.width and game.physics.p2.pxm(sprite.width) Link to comment Share on other sites More sharing options...
Luis Felipe Posted April 4, 2014 Share Posted April 4, 2014 Have a look in the phaser examples under the "Debug" section. For sprite bounds you can use: game.debug.spriteBounds(sprite); Link to comment Share on other sites More sharing options...
ZoomBox Posted April 5, 2014 Author Share Posted April 5, 2014 Those ideas are great, thank you.But I was wondering if there was a way to do it in every cases: I have multiple shapes (rectangles and polygons) and I would like to be able to get each width of bodies.For example: I have two sprites with their bodies (rectangular body or polygon and maybe a circle), and I want to be able to stick them (the bodies) one on top of each other precisely.So your solutions could work in some cases but not in every cases (I will still try them monday).I hope someone could give me the answer. Link to comment Share on other sites More sharing options...
JP91 Posted April 5, 2014 Share Posted April 5, 2014 mmmm I do not know you are trying to do,anyway in sprite.body.data.shapes[] there is the information of the current shape. Link to comment Share on other sites More sharing options...
ZoomBox Posted April 7, 2014 Author Share Posted April 7, 2014 Hey.Thank you for your answer.I found interesting things in body.data.vectices BUT there is a big problem: For those coordinates to be OK, I have to multiply them by 20. I don't know why, I haven't resize anything. I will see what happen here. Link to comment Share on other sites More sharing options...
ZoomBox Posted April 7, 2014 Author Share Posted April 7, 2014 It works great with the body.data.shapes[0].verctices but I can't manage to find why I have to multiply each value by 20.My bodies are rescaled by 0.3 not by 1/20 (0.05)... I don't understand. Link to comment Share on other sites More sharing options...
JP91 Posted April 7, 2014 Share Posted April 7, 2014 you can use game.physics.p2.pxm () that converts pixels to meters. and game.physics.p2.pxmi () the same but with a negative value,and game.physics.p2.mpx () meters to pixels. Link to comment Share on other sites More sharing options...
ZoomBox Posted April 7, 2014 Author Share Posted April 7, 2014 Oh my friend you're very helpful. I'll try it tomorow but it looks like a plausible solution. Edit:Finally, it didn't worked... I'll stick with my "x20" and I'll see later. Link to comment Share on other sites More sharing options...
rich Posted April 14, 2014 Share Posted April 14, 2014 It works great with the body.data.shapes[0].verctices but I can't manage to find why I have to multiply each value by 20.My bodies are rescaled by 0.3 not by 1/20 (0.05)... I don't understand. P2 (like most physics systems) uses meters for distances and coordinates, not pixels. So every time a value is given to, or extracted from p2 it is converted from meters to pixels using a value of 20px/m. This is regardless of your object scale. Edit: Also worth adding that physics world coordinates are essentially the opposite of screen coordinates, i.e. 0x 0y isn't the top left as far as p2 is concerned. Link to comment Share on other sites More sharing options...
ZoomBox Posted April 15, 2014 Author Share Posted April 15, 2014 Thank you for your reply. I'm now reassured it makes sence. Awesome engine, bye ! :-) Link to comment Share on other sites More sharing options...
Recommended Posts