Used to map inputs (from keyboard, mouse, or gamepad) into actions.
setAction allows for set-and-forget mappings. Good for one-off games.
Example:
// bind action jump
like.load() {
like.input.setAction('jump', ['KeyX', 'Space', 'ButtonBottom'])
}
like.actionpressed(action) {
if (action == 'jump') {
player.tryJumping();
}
}
For more sophisticated games, see also:
These allow for programmatic binding based on events. For example:
let currentlyMapping = 'jump';
// Watch for gamepad and keyboard events
like.keypressed = (code) => {
if (currentlyMapping) {
like.input.appendToAction(currentlyMapping, code);
}
}
like.gamepadpressed = (name) => {
if (currentlyMapping) {
like.input.appendToAction(currentlyMapping, name);
}
}
// Print some info about the current mapping
like.draw = () => {
if (currentlyMapping) {
myGame.statusLine =
`Mapped ${like.input.getActionMapping(currentlyMapping)} to ${currentlyMapping}`
}
}
This is the easiest way to set-and-forget input => action mapping.
Or, it's a helper to remove actions -- setAction(action, [])
will simply clear the action away.
For input strings:
MouseLeft, MouseRight, or MouseMiddle.KeyA, KeyB, ...Digit0, Digit1, ...ArrowLeft, ArrowRight, ArrowUp, ArrowDownShiftLeft, ShiftRightSpaceMinusEqual (also has a plus sign)BracketLeft and BracketRightSemicolonQuoteBackquote (also has tilde)BackslashCommaPeriodSlashBackspaceEnter
Used to map inputs (from keyboard, mouse, or gamepad) into actions.
setAction allows for set-and-forget mappings. Good for one-off games.
Example:
For more sophisticated games, see also:
These allow for programmatic binding based on events. For example: