Class VirtualButton

java.lang.Object
com.codename1.gaming.VirtualButton

public class VirtualButton extends Object

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.

  • 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).
    • 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()