Note that there are some explanatory texts on larger screens.

plurals
  1. PONeeds advice on Libgdx Scaling
    primarykey
    data
    text
    <p>This might be a simple question being addressed somewhere, but I can’t find it. I do hope someone can lead me to the right path. The design resolution for my application is 800x480. To maintain the correct aspect ratio on devices with higher resolution, I followed <a href="https://github.com/libgdx/libgdx/wiki/Scene2d" rel="nofollow" title="this post">this post</a> and managed to get the “black bar” (I used blue for testing) on both side on a bigger screen (nexus 7). However, it seems that the stage is not scaled to cover the screen. Please see screen shot bellow, blue colour are the Gdx.gl.glClearColor(0.5f, 1, 1, 1); black rectangular (800x480) is the actual Sprite. </p> <p><a href="https://lh5.googleusercontent.com/-Nkfyt4113ag/UltLB-LG6wI/AAAAAAAAAC0/jFgP7J1oj6A/s1152/stage%2520not%2520scale%2520to%2520full%2520screen.png" rel="nofollow">Link to image</a></p> <p>I am not sure where I went wrong. Any help is much appreciated. Code below:</p> <pre><code>private SpriteBatch batch; private Texture splashTexture; private Sprite splashSp; TextureRegion splashTr; Stage stage; @Override public void create() { stage = new Stage(); batch = new SpriteBatch(); splashTexture = new Texture(Gdx.files.internal("img/splashTexture.png")); splashTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); TextureRegion splashTr = new TextureRegion(splashTexture, 0, 0, 800, 480); splashSp = new Sprite(splashTr); Gdx.app.log("myapp", "Creating game"); } @Override public void render() { Gdx.gl.glClearColor(0.5f, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); stage.draw(); batch.begin(); batch.draw(splashSp, 0, 0); batch.end(); } @Override public void resize(int width, int height) { Gdx.app.log("myapp", "width:" + width + " height:" + height); Vector2 size = Scaling.fit.apply(800, 480, width, height); int viewportX = (int)(width - size.x) / 2; int viewportY = (int)(height - size.y) / 2; int viewportWidth = (int)size.x; int viewportHeight = (int)size.y; Gdx.app.log("myapp", "viewportWidth:" + viewportWidth + " viewportHeight:" + viewportHeight); Gdx.app.log("myapp", "viewportX:" + viewportX + " viewportY:" + viewportY); Gdx.gl.glViewport(viewportX, viewportY, viewportWidth, viewportHeight); stage.setViewport(800, 480, true); Gdx.app.log("myapp", "Resizing game"); } </code></pre>
    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