Note that there are some explanatory texts on larger screens.

plurals
  1. POLibgdx resize window on android to fill screen
    primarykey
    data
    text
    <p>I am trying to fill the resize function that comes with Libgdx to fit all of the android screens. </p> <p>The best solution I have seen so far is this tutorial: <a href="http://www.java-gaming.org/index.php?topic=25685.0" rel="nofollow">http://www.java-gaming.org/index.php?topic=25685.0</a> but when I run it on my Galaxy S3 the buttons are really tiny and just overall the whole game is tiny where on the desktop version it is big and the way I want it to be. My resize code right now is:</p> <pre><code>@Override public void resize(int width, int height) { float aspectRatio = (float)width/(float)height; float scale = 2f; Vector2 crop = new Vector2(0f, 0f); if(aspectRatio &gt; ASPECT_RATIO) { scale = (float)height/(float)VIRTUAL_HEIGHT; crop.x = (width - VIRTUAL_WIDTH*scale)/2f; } else if(aspectRatio &lt; ASPECT_RATIO) { scale = (float)width/(float)VIRTUAL_WIDTH; crop.y = (height - VIRTUAL_HEIGHT*scale)/2f; } else { scale = (float)width/(float)VIRTUAL_WIDTH; } float w = (float)VIRTUAL_WIDTH*scale; float h = (float)VIRTUAL_HEIGHT*scale; viewport = new Rectangle(crop.x, crop.y, w, h); } </code></pre> <p>My render code is: </p> <pre><code>@Override public void render() { // update camera camera.update(); // set viewport Gdx.gl.glViewport((int) viewport.x, (int) viewport.y, (int) viewport.width, (int) viewport.height); // clear previous frame Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); ScreenManager.updateScreen(); sb.begin(); ScreenManager.renderScreen(sb); sb.end(); } </code></pre> <p>And my variables are: </p> <pre><code>private static final int VIRTUAL_WIDTH = 600; private static final int VIRTUAL_HEIGHT = 800; private static final float ASPECT_RATIO = (float)VIRTUAL_WIDTH/(float)VIRTUAL_HEIGHT; public static BitmapFont FONT; private OrthographicCamera camera; private Rectangle viewport; private SpriteBatch sb; </code></pre> <p>Like I said, when I run the desktop version it works fine but when I run it on my Galaxy S3 (Screen Dim: 1,280 x 720), the game is zoomed out a lot, and it crops out the tops and sides of the game which is not what I want at all.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload