سؤال

I have a problem with my resizing method in libgdx, when I ran my game on my phone all works fine, but when I ran the game in another phone which is more bigger all is getting smaller and it just look bad.

Here is my resizing method:

@Override
public void resize(int width, int height) {

    ...

    camera.viewportHeight = height /  1.1f;
    camera.viewportWidth = width / 1.1f;



    stage.setViewport(width, height, true);

        table.invalidateHierarchy();
        table.setSize(width, height);
        table2.invalidateHierarchy();
        table2.setSize(width, height);
        table3.invalidateHierarchy(); 
        table3.setSize(width, height);
        table4.invalidateHierarchy();
        table4.setSize(width, height);

}

And this method just give a bad effect. How can I fix this?

هل كانت مفيدة؟

المحلول

The perfect question to introduce Viewport, which has been added today.

Viewports are made especially to deal with this very problem. Have a look at this news and the wiki page to see how those work.

However, those are only available in the nightly build.

What you are actually doing at the moment, is implementing the "ScreenViewport" yourself, which always keeps the size of the screen, which leads to no stretching, but it will show more or less of your world.

What you are probably looking for, is FitViewport or maybe StretchViewport. Those offer you a virtual screen size and will scale this to fit your screen.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top