Reputation: 1858
I set my orthographic camera for my box2d world to 21 width and 12 height, this is equivalent to 1 meter = 1 pixel. But the problem is that I have another ortho camera for my sprites and bitmapfonts (for my SpriteBatch) which is 640X360 pixels, so for example I have a 1x1 meter body then how can I render the texture on top of that body as big as 1x1 meter into pixel?
Upvotes: 2
Views: 429
Reputation: 973
First, don't think of camera units as pixels,I suggest you use a single camera and "units per meter" multiplier for conversion.
set your camera's width and height as how much of your world you wish to be seen. set size of your sprites using setSize()
method, it will scale your texture to be seen as the proportion of world; if you want one meter to be 1/10 of screen height
set a variable like
upm= camera.viewportHeight/10 //units per meter
so that you can set size of e.g. 2×1 box as
myBoxSprite.setSize(2*upm,upm)
. box2d Body
has setUserData()
and getUserData()
methods which you can use to link your sprites(visual game objects) to their box2d body(physical body) and access it when needed and also make referrence variables in your game object to point to box2d body and sprite like so you can use them when you want to change position of sprite to be drawn according to body's position
p.s. this is my first answer on SOF so excuse me if it is not as it has to be.
Upvotes: 0