title: How do I create an orthographic camera that correctly scales my sprites/textures with libgdx?
body: <p>I'm creating a game with libgdx that I want to run at a higher resolution on the desktop, but I want it to scale everything down correctly when I run it on android at smaller resolutions. I've read that the best way to do this is to not use a pixel perfect camera, and instead to use world coordinates, but I'm not sure how to correctly do that.</p>
  
  <p>This is the code I have right now:</p>
  
  <pre><code>@Override
  public void create() {
      characterTexture = new Texture(Gdx.files.internal("character.png"));
      characterTextureRegion = new TextureRegion(characterTexture, 0, 0,  100, 150);
      batch = new SpriteBatch();
  
  
      Gdx.gl10.glClearColor(0.4f, 0.6f, 0.9f, 1);
  
      float aspectRatio = (float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight();
      camera= new OrthographicCamera(aspectRatio, 1.0f);
  
  }
  
  @Override
  public void render() {
      GL10 gl = Gdx.graphics.getGL10();
  
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  
      camera.update();
      camera.apply(gl);
      batch.setProjectionMatrix(camera.combined);
  
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  
      draw();
  }
  
  private void draw() {
      //batch.getProjectionMatrix().set(camera.combined);
      batch.begin();
  
      batch.draw(characterTextureRegion, 0, 0, // the bottom left corner of the box, unrotated
              1f, 1f, // the rotation center relative to the bottom left corner of the box
              0.390625f, 0.5859375f, // the width and height of the box
              1, 1, // the scale on the x- and y-axis
              0); // the rotation angle
  
  
      batch.end();
  }
  </code></pre>
  
  <p>The texture I'm use is 256x256 with the actual image in it being 100x150.</p>
  
  <p>This is the result I get when I run the game: <a href="http://i.imgur.com/HV9Bi.png" rel="nofollow">http://i.imgur.com/HV9Bi.png</a></p>
  
  <p>The sprite that gets rendered is massive, considering this is the original image: <a href="http://i.imgur.com/q1cZT.png" rel="nofollow">http://i.imgur.com/q1cZT.png</a></p>
  
  <p>What's the best way to go about making it so that the sprites get rendered at their original size while still keeping the ability to have the game scale correctly when played in different resolutions?</p>
  
  <p>I've only found two solutions,  both of which I don't like.</p>
  
  <ol>
  <li>The image showed up how it was supposed to if I used pixel coordinates for the camera, but then that didn't scale at all when I put it on my phone with a different resolution.</li>
  <li>I can scale the texture region down when I draw it, but it seems like there is a better way because it is extremely tedious trying to figure out the correct number to scale it by.</li>
  </ol>