Customizing key bindings
A big part with input management in a game is allowing the user to customize how he interacts with it, like the keys. Most of the time, you can find the most popular key bindings and see them written directly in the code. But there will always be people that want to do stuff their way.
We have to provide tools in order to dynamically bind the keys to specific actions. With the command queue introduced in the previous sections, this becomes a much easier task to accomplish.
With the command queue, we already define specific actions for a specific key. The difference is that right now, we have it hardcoded as follows:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) commands.push(moveLeft); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) ...
Get SFML Game Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.