Class Input

java.lang.Object
com.codename1.gaming.platformer.Input

public final class Input extends Object

The buttons an actor reads, as bits of one int per tick.

A tick's input is a single int, which is what makes a run cheap to record (InputLog) and exact to replay. Touch controls, a keyboard and a gamepad all produce the same bits, so the simulation never knows which one a player used.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Activate what the actor stands at: a lever, a door, a sign.
    static final int
    Every defined bit.
    static final int
    Use the jetpack or glide while held (an ability decides which).
    static final int
    Dash.
    static final int
    Down: crouch, climb down, drop through a one-way platform with JUMP.
    static final int
    Use the weapon.
    static final int
    Jump.
    static final int
    Move left.
    static final int
    Move right.
    static final int
    Run while held.
    static final int
    Up: climb, look up, enter a door.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    held(int bits, int button)
    Whether a button is held this tick.
    static int
    horizontal(int bits)
    The horizontal direction held.
    static boolean
    pressed(int bits, int previous, int button)
    Whether a button went down this tick.
    static int
    vertical(int bits)
    The vertical direction held.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • held

      public static boolean held(int bits, int button)

      Whether a button is held this tick.

      Parameters
      • bits: this tick's input
      • button: one of the button constants
      Returns

      true while held

    • pressed

      public static boolean pressed(int bits, int previous, int button)

      Whether a button went down this tick.

      Parameters
      • bits: this tick's input
      • previous: the previous tick's input
      • button: one of the button constants
      Returns

      true on the press edge

    • horizontal

      public static int horizontal(int bits)

      The horizontal direction held.

      Parameters
      • bits: this tick's input
      Returns

      -1 for left, 1 for right, 0 for neither or both

    • vertical

      public static int vertical(int bits)

      The vertical direction held.

      Parameters
      • bits: this tick's input
      Returns

      -1 for up, 1 for down, 0 for neither or both