title: Libgdx Box2D pixel to meter conversion?
body: <p>When trying to program a game using Box2D, I ran into a problem with Box2D. I filled in pixel numbers for the lengths of the the textures and sprites to create a box around it. Everything was at the right place, but for some reason everything went very slowly. By looking on the internet I found out that if you didn't convert pixels to meters box2d might handle shapes as very large objects. this seemed to be a logical cause of everything moving slowly.</p>
  
  <p>I found similar questions on this site, but the answers didn't really seem to help out. in most of the cases the solution was to make methods to convert the pixel numbers to meters using a scaling factor. I tried this out, but everything got misplaced and had wrong sizes. this seemed logical to me since the numbers where changed but had the same meaning. </p>
  
  <p>I was wondering if there is a way to make the pixels mean less meters, so everything whould be at the same place with the same (pixel) size, but mean less meters.
  If you have a different way which you think might help, I whould also like to hear it..</p>
  
  <p>Here is the code i use to create the camera</p>
  
  <pre><code>        width = Gdx.graphics.getWidth() / 5;
          height = Gdx.graphics.getHeight() / 5;
  
          camera = new OrthographicCamera(width, height);
          camera.setToOrtho(false, 1628, 440);
          camera.update();
  </code></pre>
  
  <p>This is the method I use to create an object:</p>
  
  <pre><code>public void Create(float X, float Y, float Width, float Height, float density, float  friction, float restitution, World world){ 
      //Method to create an item
      width = Width;
      height = Height;
  
      polygonDef = new BodyDef();
      polygonDef.type = BodyType.DynamicBody;
      polygonDef.position.set(X + (Width / 2f), Y + (Height / 2f));
  
      polygonBody = world.createBody(polygonDef);
  
      polygonShape = new PolygonShape();
      polygonShape.setAsBox(Width / 2f, Height / 2f);
  
      polygonFixture = new FixtureDef();
      polygonFixture.shape = polygonShape;
      polygonFixture.density = density;
      polygonFixture.friction = friction;
      polygonFixture.restitution = restitution;
  
      polygonBody.createFixture(polygonFixture);
  }
  </code></pre>
  
  <p>To create an item, in this case a table, I use the following:</p>
  
  <pre><code>    Table = new Item();
      Table.Create(372f, 60f, 152f, 96f, 1.0f, 0.2f, 0.2f, world);
  </code></pre>
  
  <p>The Sprites are drawn on the item by using  the following method:</p>
  
  <pre><code>public void drawSprite(Sprite sprite){
      polygonBody.setUserData(sprite);
      Utils.batch.begin();
      if(polygonBody.getUserData() instanceof Sprite){
          Sprite Sprite = (Sprite) polygonBody.getUserData();
          Sprite.setPosition(polygonBody.getPosition().x - Sprite.getWidth() / 2, polygonBody.getPosition().y - Sprite.getHeight() / 2);
          Sprite.setRotation(polygonBody.getAngle() * MathUtils.radiansToDegrees);
          Sprite.draw(Utils.batch);
      }
      Utils.batch.end();
  }
  </code></pre>
  
  <p>The sprites also have pixel sizes.</p>
  
  <p><strong>Using this methods it displays the images at the right places, but everything moves slowly.
  I was wondering how or if I whould have to change this to make the objects move correctly, and / or mean less. Thanks in advance.</strong></p>