title: Libgdx virtual width and height
body: <p>I am following this tutorial: <a href="http://www.java-gaming.org/index.php?topic=25685.new" rel="nofollow">http://www.java-gaming.org/index.php?topic=25685.new</a> and using virtual widths and heights.</p>
  
  <p>My requirements are:</p>
  
  <ol>
  <li><p>Background image should fill the entire screen</p></li>
  <li><p>Aspect ratio of game assets should be preserved : My virtual width, height are: 800,600. One of the game assets has initial virtual position: 450,20, so I set: </p>
  
  <pre><code>playerSprite.setPosition(450, 20);//I assume (450,20) would be virtual
  </code></pre></li>
  </ol>
  
  <p>The problem is that player (game asset) is not visible when I set my window size to 200X200 through main function. I thought assets (size and positions) would automatically scale preserving aspect ratios. However, when I set my screen size to 800X600 and then resized it to 200X200 (manually) then the assets were scaled and positioned properly. I do not what is the difference between setting 200X200 in the main function vs. resizing bigger window to 200X200 afterwards.</p>
  
  <p><strong>My render function:</strong></p>
  
  <pre><code>Gdx.gl.glClearColor(0, 0, 0, 
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  //Stretch background to cover the entire screen
  if(backgroundTR!=null){
  //Gdx.gl.glViewport(0, 0, screenWidth, screenHeight);
      batch.begin();
  batch.draw(backgroundTR, 0, 0,screenWidth,screenHeight);
  batch.end();
  }
  
  //Preserve aspect ratios of assets as per the tutorial
  orthographicCamera.update();
  orthographicCamera.apply(Gdx.gl10);
  Gdx.gl.glViewport((int)viewport.x, (int)viewport.y, (int)viewport.width, (int)viewport.height);
  
  batch.begin();
  batch.draw(titleTR,160f,450f);
      //batch.draw(playerTR,450f,20f);
  playerSprite.draw(batch);
  batch.end();
  </code></pre>
  
  <p>The background is not filled either. Any help?</p>