Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class Input

  1. Object
  2. Input

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.

Fields

public static final int LEFT = 1Move left.
public static final int RIGHT = 2Move right.
public static final int UP = 4Up: climb, look up, enter a door.
public static final int DOWN = 8Down: crouch, climb down, drop through a one-way platform with JUMP.
public static final int JUMP = 16Jump.
public static final int RUN = 32Run while held.
public static final int DASH = 64Dash.
public static final int FIRE = 128Use the weapon.
public static final int ACTIVATE = 256Activate what the actor stands at: a lever, a door, a sign.
public static final int ALT = 512Use the jetpack or glide while held (an ability decides which).
public static final int ALL = 1023Every defined bit.

Methods

public static boolean held(int bits, int button)Whether a button is held this tick.
public static boolean pressed(int bits, int previous, int button)Whether a button went down this tick.
public static int horizontal(int bits)The horizontal direction held.
public static int vertical(int bits)The vertical direction held.

Inherited methods

Field details

LEFT

public static final int LEFT = 1
Move left.

UP

public static final int UP = 4
Up: climb, look up, enter a door.

DOWN

public static final int DOWN = 8
Down: crouch, climb down, drop through a one-way platform with JUMP.

JUMP

public static final int JUMP = 16
Jump.

RUN

public static final int RUN = 32
Run while held.

DASH

public static final int DASH = 64
Dash.

FIRE

public static final int FIRE = 128
Use the weapon.

ACTIVATE

public static final int ACTIVATE = 256
Activate what the actor stands at: a lever, a door, a sign.

ALT

public static final int ALT = 512
Use the jetpack or glide while held (an ability decides which).

ALL

public static final int ALL = 1023
Every defined bit.

Method details

held

public static boolean held(int bits, int button)
Whether a button is held this tick.

Parameters

bits int
this tick’s input
button int
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 int
this tick’s input
previous int
the previous tick’s input
button int
one of the button constants

Returns

true on the press edge

horizontal

public static int horizontal(int bits)
The horizontal direction held.

Parameters

bits int
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 int
this tick’s input

Returns

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