1
\$\begingroup\$

I want to use scene2d for creating a GUI for a libGDX game. In scene2d all sizes are provided in pixel units (instead of percentages). So I wonder what is the best approach to deal with different screen resolutions? Two solutions came into my mind and I wonder how to proceed:

  • Use a fixed resolution for the GUI (e.g. 1920x1080), optimize all widgets for this size and let the viewport do the rest (so there will be super- or subsampling)

  • or write a resizing logic for the gui to properly adapt the widget sizes and positions to the screen's resolution

Is there any known best practice how to deal with this problem?

\$\endgroup\$
1
\$\begingroup\$

The Android-style would be to create custom layouts for each viewport size. This limits you, of course, to only handling a fixed set of viewport sizes but there are only a limited number of monitor resolutions and each one would look its best.

The fixed resolution master layout used with viewports that scale all the contents will work to a degree (I use this here at work on one project), but texts will suffer a little at the smallest percentages. I find that you can limit the monitor requirements to enforce a minimum size that looks good and lose almost no potential customers in today's gaming environment.

\$\endgroup\$
1
\$\begingroup\$

libgdx provide a utility class called viewport to deal with different screen resolutions problem , each time the screen resolution changes you have to update the viewport:

private Viewport viewport;
private Camera camera;

public void create() {
    camera = new PerspectiveCamera();
    viewport = new FitViewport(800, 480, camera);
}

Whenever a resize event occurs, the viewport needs to be informed about it and updated. This will automatically recalculate the viewport parameters and update the camera:

public void resize(int width, int height) {
    viewport.update(width, height);
}

For further informations take a look at https://github.com/libgdx/libgdx/wiki/Viewports

\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer but this is what I already tried to sum up with my first approach ("let the viewport do the rest"). The question was more about best practice for this problem in general. \$\endgroup\$ – Sebastian Sep 19 '16 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.