O'Reilly logo

Building a 3D Game with LibGDX by Elmar van Rijnswou, Andreas Krühlmann, Sebastián Di Giuseppe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required