Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement InputMapper #2705

Merged
merged 6 commits into from
Jul 25, 2023
Merged

feat: Implement InputMapper #2705

merged 6 commits into from
Jul 25, 2023

Conversation

eonarheim
Copy link
Member

@eonarheim eonarheim commented Jul 24, 2023

===:clipboard: PR Checklist :clipboard:===

  • 📌 issue exists in github for these changes
  • 🔬 existing tests still pass
  • 🙈 code conforms to the style guide
  • 📐 new tests written and passing / old tests updated with new scenario(s)
  • 📄 changelog entry added (or not needed)

==================

This PR implements a new input mapper for excalibur which is useful for mapping multiple input sources into specific commands. This can be used to enable accessibility for your users adding ways for them to provide different inputs!

This examples shows how to map multiple types of input for the same action!

const moveRight = (amount: number) => { actor.vel.x = 100 * amount }
const moveLeft = (amount: number) => { actor.vel.x = -100 * amount }
const moveUp = (amount: number) => { actor.vel.y = -100 * amount }
const moveDown = (amount: number) => { actor.vel.y = 100 * amount }
engine.inputMapper.on(({keyboard}) => keyboard.isHeld(ex.Keys.ArrowRight) ? 1 : 0, moveRight);
engine.inputMapper.on(({gamepads}) => gamepads.at(0).isButtonPressed(ex.Buttons.DpadRight) ? 1 : 0, moveRight);
engine.inputMapper.on(({gamepads}) => gamepads.at(0).getAxes(ex.Axes.LeftStickX) > 0 ? gamepads.at(0).getAxes(ex.Axes.LeftStickX) : 0, moveRight);

@github-actions github-actions bot added the enhancement Label applied to enhancements or improvements to existing features label Jul 24, 2023
@eonarheim eonarheim merged commit 331b658 into main Jul 25, 2023
@eonarheim eonarheim deleted the feature/input-mapper branch July 25, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Label applied to enhancements or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant