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

public class InputMapper

  1. Object
  2. InputMapper

Reads the keyboard, a gamepad and the on-screen controls of a com.codename1.gaming.GameInput into the Input bits a PlatformWorld steps with. Keyboard: arrows or WASD move, space/K jump, R run, Z/J dash, X/L fire, E activate, C alternate (jetpack, glide). Gamepad: stick or d-pad move, A jump, B dash, X fire, Y activate, right shoulder run, left shoulder alternate. On-screen buttons send the key codes above.

Subclass it or set other key codes to remap; the world only ever sees bits, so a replay is the same whichever device produced it.

Constructors

public InputMapper()

Methods

public static InputMapper forPlayer(int player)A mapper for one player of a shared-screen game.
public int getPlayer()Which player this mapper reads for.
public void setJumpKeys(int... keys)The keys that jump.
public void setFireKeys(int... keys)The keys that fire.
public void setDashKeys(int... keys)The keys that dash.
public void setAlwaysRun(boolean alwaysRun)Runs without holding a key, as touch players expect.
public int getJumpKey()The key code an on-screen jump button should send.
public int getFireKey()The key code an on-screen fire button should send.
public int getDashKey()The key code an on-screen dash button should send.
public int read(GameInput in)Reads the current input.

Inherited methods

Constructor details

InputMapper

public InputMapper()

Method details

forPlayer

public static InputMapper forPlayer(int player)
A mapper for one player of a shared-screen game. Player 0 has the left of the keyboard (WASD to move, Space or F to jump, G to dash, H to fire, E to act) and the first gamepad; player 1 has the right (the arrows, Enter or / to jump, period to dash, comma to fire, M to act) and the second gamepad. A mapper made with the constructor reads every key and every gamepad, for a single player.

Parameters

player int
0 or 1

Returns

a new mapper

getPlayer

public int getPlayer()
Which player this mapper reads for.

Returns

the player from forPlayer, or -1 for every key and gamepad

setJumpKeys

public void setJumpKeys(int... keys)
The keys that jump. On-screen buttons should send the first.

Parameters

keys int...
key codes

setFireKeys

public void setFireKeys(int... keys)
The keys that fire.

Parameters

keys int...
key codes

setDashKeys

public void setDashKeys(int... keys)
The keys that dash.

Parameters

keys int...
key codes

setAlwaysRun

public void setAlwaysRun(boolean alwaysRun)
Runs without holding a key, as touch players expect.

Parameters

alwaysRun boolean
true to always run

getJumpKey

public int getJumpKey()
The key code an on-screen jump button should send.

Returns

a key code

getFireKey

public int getFireKey()
The key code an on-screen fire button should send.

Returns

a key code

getDashKey

public int getDashKey()
The key code an on-screen dash button should send.

Returns

a key code

read

public int read(GameInput in)
Reads the current input.

Parameters

in GameInput
the view’s input state

Returns

Input bits