Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class VirtualButton

  1. Object
  2. VirtualButton

An on-screen touch button. Add one with TouchControls#addButton(int, float, float, float); while a finger is on it the framework holds down the key code it is mapped to, so GameInput#isKeyDown(int) and GameInput#wasKeyPressed(int) report it exactly as a hardware key. Map it to a game action with com.codename1.ui.Display#getKeyCode(int) (e.g. Display.getInstance().getKeyCode(Display.GAME_FIRE)) or to any key code of your own.

The position and radius are in the GameView’s pixel coordinates.

Methods

public VirtualButton setLabel(String label)Optional short label drawn on the button (for example “A” or “Fire”).
public VirtualButton setColor(int argb)The ARGB color the button is tinted (default a translucent white).
public VirtualButton setLabelColor(int argb)The ARGB colour of the label (default a dark grey).
public int getLabelColor()
public boolean isPressed()
public int getKeyCode()
public float getCenterX()
public float getCenterY()
public float getRadius()
public String getLabel()
public int getColor()

Inherited methods

Method details

setLabel

public VirtualButton setLabel(String label)
Optional short label drawn on the button (for example “A” or “Fire”).

setColor

public VirtualButton setColor(int argb)
The ARGB color the button is tinted (default a translucent white).

setLabelColor

public VirtualButton setLabelColor(int argb)
The ARGB colour of the label (default a dark grey). The label is drawn over the button in this colour and is not tinted by setColor, so a light label stays readable on a dark, translucent button.

getLabelColor

public int getLabelColor()

isPressed

public boolean isPressed()

getKeyCode

public int getKeyCode()

getCenterX

public float getCenterX()

getCenterY

public float getCenterY()

getRadius

public float getRadius()

getLabel

public String getLabel()

getColor

public int getColor()