Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class TouchControls
- Object
- TouchControls
On-screen controls for touch devices: an optional analog VirtualJoystick plus
any number of VirtualButtons. The framework draws them over the game and routes
touches into the view’s GameInput, so a touch game reads input exactly like a
keyboard game – GameInput#isGameKeyDown(int), GameInput#isKeyDown(int) and
the joystick’s analog GameInput#getAxisX() / getAxisY() all work whether the
player is on a phone or a desktop.
Get the instance from GameView#getControls() and add the controls you want,
placing them in the view’s pixel coordinates (origin at the top left):
int fire = Display.getInstance().getKeyCode(Display.GAME_FIRE);
getControls().addJoystick(140, getHeight() - 140, 90);
getControls().addButton(fire, getWidth() - 120, getHeight() - 120, 55).setLabel("A");
Multi-touch is supported, so the player can steer with the stick and press a button at the same time.
Fields
public static final int LEFT = 0 | Horizontal anchor: pin to the left safe-area edge. |
public static final int CENTER = 1 | Horizontal/vertical anchor: center on the safe area. |
public static final int RIGHT = 2 | Horizontal anchor: pin to the right safe-area edge. |
public static final int TOP = 0 | Vertical anchor: pin to the top safe-area edge. |
public static final int BOTTOM = 2 | Vertical anchor: pin to the bottom safe-area edge. |
Methods
Inherited methods
Field details
LEFT
public static final int LEFT = 0CENTER
public static final int CENTER = 1RIGHT
public static final int RIGHT = 2TOP
public static final int TOP = 0BOTTOM
public static final int BOTTOM = 2Method details
addJoystick
public VirtualJoystick addJoystick(float centerX, float centerY, float radius)addJoystick
public VirtualJoystick addJoystick(float radius, int hAlign, int vAlign, float margin)hAlign is one of #LEFT / #CENTER / #RIGHT, vAlign one of #TOP /
#CENTER / #BOTTOM, and margin is the gap from the safe-area edges.addButton
public VirtualButton addButton(int keyCode, float centerX, float centerY, float radius)com.codename1.ui.Display#getKeyCode(int) to map a game action.addButton
public VirtualButton addButton(int keyCode, float radius, int hAlign, int vAlign, float margin)#addJoystick(float, int, int, float)), so it stays inside the safe area and
follows rotation automatically.setVisible
public void setVisible(boolean visible)isVisible
public boolean isVisible()getJoystick
public VirtualJoystick getJoystick()