Now that we have access to the player's keyboard, we can learn how to move game objects. Let's move the player character to the right when the right arrow key is pressed on the keyboard. We will stop moving the hero when the right arrow key is released:
- Create a global Vector2f called playerPosition, right after heroSprite.
- Create a Boolean data type called playerMoving and set it to false.
- In the updateInput function, we will check whether the right key has been pressed or released. If the button is pressed, we set playerMoving to true. If the button is released, then we set playerMoving to false.
The updateInput function should be as follows:
void updateInput() { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::Right...