Jump to content

  • Log In with Google      Sign In   
  • Create Account


Libgdx camera - pixel issues


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 levela   Members   -  Reputation: 114

Like
0Likes
Like

Posted 27 April 2013 - 07:58 AM

Hiho!
 

I am a game designer student who started working with box2d and Libgdx recently. My game idea relies on Box2D heavily, so I spent about a week learning Box2dWeb (which is the JavaScript port of Box2d), and learned hopefully most of the things that I am going to need

in the development process. You can see the end result here

 

When I got done with this, I took a dive into libgdx. Read a lot of tutorials and documentation, and managed to get most of the things already working, but I am stuck with the pixel to meter (and vica-versa) scaling system, therefore I can't get it working on my Android device.

 

Using Box2dWeb I could solve the scaling problem by setting up a scale variable, and dividing and multiplying with it. According to the web, 30pixel should be equivalent 1 meter, so I did the following:

SCALE = 30;

...

var bodyDef			= new box2d.b2BodyDef();
    bodyDef.type		= box2d.b2Body.b2_staticBody;	
    bodyDef.position.x	        = 400 / SCALE; 
    bodyDef.position.y	        = 600 / SCALE;
    bodyDef.userData            = 'Ground';

var fixDef = new box2d.b2FixtureDef();
fixDef.density = 5;
fixDef.friction = 0.5;
fixDef.restitution = 0.9;

fixDef.shape = new box2d.b2CircleShape(50 / SCALE);

 

 

And after assigning a bitmap to it, it matched the shape of the box!



Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS