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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.