It looks like you're new here. If you want to get involved, click one of these buttons!
How do I convert pixels to meters? Suppose you have a sprite for a character that is 100x100 pixels. You decide to use a scaling factor that is 0.01. This will make the character physics box 1m x 1m. So go make a physics box that is 1x1. Now suppose the character starts out at pixel coordinate (345,679). So position the physics box at (3.45,6.79). Now simulate the physics world. Suppose the character physics box moves to (2.31,4.98), so move your character sprite to pixel coordinates (231,498). Now the only tricky part is choosing a scaling factor. This really depends on your game. You should try to get your moving objects in the range 0.1 - 10 meters, with 1 meter being the sweet spot. |
Comments
In Gideros Studio, go to Help and Choose -> API Documentation, go to b2.setScale()
In your example you could use:
Hope that helps
Likes: gorkem
@twisttap best of luck man, sounds cool keep up the good work
Here's more information:
http://www.giderosmobile.com/forum/discussion/comment/3231#Comment_3231
TLDR;
There is a funciton b2.setScale(scale) using which you can scale all pixel units, by default it's value is 30, so all your objects are already scaled. As I understood, then it's done internally and nothing additional is required from you, then simply provide scale.
It changes the ratio between 1m and 1 pixel in box2d simulation. It will change nothing from visual point of view. Only how simulations behave and maybe even get some performance, if internal calculations would be performed in interval between 10 and 0.1.
For example if your largest object is 300px and your smallest object is 3px, then by setting scale to 30, box2d would handle them as they were 10 units and 0.1. It won't change the actual size. But simulations may behave differently. Try setting scale 0 and look and dynamic object moving and collisions. They should be pretty jigged.