Analog sticks on mobile and platform recognition

The game runs on mobile without any problem on mid-end devices, and it should work fine on most devices too. However, our game isn't really suited to play on mobiles because of the input. We can fix that by adding analog sticks to the screens, as usual for a lot of games.

We'll create a new widget to handle this controller.

Let's fire up GameUI.java:

public class GameUI { 
   ... 
   private ControllerWidget controllerWidget; 
 
   public void setWidgets() { 
       ... 
       if (Gdx.app.getType() ==
       Application.ApplicationType.Android) controllerWidget = new
       ControllerWidget(); 
   } 
 
   public void configureWidgets() { 
       ... 
       if (Gdx.app.getType() ==
       Application.ApplicationType.Android)
       controllerWidget.addToStage(stage); 
   } 
} 

Addition ...

Get Building a 3D Game with LibGDX now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.