Skip to content
Thomas Cashman edited this page Nov 16, 2016 · 4 revisions

The common method for adding UI to your mini2Dx game is to use the mini2Dx-ui framework, however LibGDX's Scene2D is also supported by the Graphics class.

Set Up

Requires mini2Dx 1.3.0 or above

First add the mini2Dx-ui dependency to your core project.

project(":core") {
        ...
        dependencies {
                ...
                compile "org.mini2Dx:mini2Dx-ui:$mini2DxVersion"
                ...
        }
}

Introduction

The principle behind mini2Dx-ui is to write your UI once and be capable of it working on every device with any input source and little code change. To achieve this, the UI framework uses a responsive design pattern (though non-responsive UI is also supported). This is explained below.

Grid System

The UI uses a grid system that splits the game window into 12 columns - similar to Bootstrap's Grid System. The UI then categorises the current game window width as a ScreenSize.

These ScreenSize values are defined as follows:

  • XS - Extra small: 0px - 765px
  • SM - Small: 768px - 991px
  • MD - Medium: 992px - 1199px
  • LG - Large: 1200px - 1599px
  • XL - Extra Large: 1600px+

Any UiElement that has a setLayout() method can be set to a column size or a pixel size. You can then specify different sizes based on the screen size. In the following example, the Column instance would take up the width of 4 columns on an XS screen, 3 columns on an MD screen and then 1 column on an XL screen.

Column column = new Column();
...
column.setLayout("xs-4c md-3x xl-1c");

For setting pixel sizes, simply replace the c with px.

column.setLayout("xs-400px md-300px xl-100px");

However, the following must be noted:

  • If no size rule is applied to the element, the default is xs-12c
  • If no size rule for the current ScreenSize exists, the element will use the closest smaller screen size.

Next steps

Clone this wiki locally