Class 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InputMapperforPlayer(int player) A mapper for one player of a shared-screen game.intThe key code an on-screen dash button should send.intThe key code an on-screen fire button should send.intThe key code an on-screen jump button should send.intWhich player this mapper reads for.intReads the current input.voidsetAlwaysRun(boolean alwaysRun) Runs without holding a key, as touch players expect.voidsetDashKeys(int... keys) The keys that dash.voidsetFireKeys(int... keys) The keys that fire.voidsetJumpKeys(int... keys) The keys that jump.
-
Constructor Details
-
InputMapper
public InputMapper()
-
-
Method Details
-
forPlayer
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: 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: key codes
-
setFireKeys
public void setFireKeys(int... keys) The keys that fire.
Parameters
keys: key codes
-
setDashKeys
public void setDashKeys(int... keys) The keys that dash.
Parameters
keys: key codes
-
setAlwaysRun
public void setAlwaysRun(boolean alwaysRun) Runs without holding a key, as touch players expect.
Parameters
alwaysRun: 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
Reads the current input.
Parameters
in: the view's input state
Returns
Inputbits
-