Search code examples
animationspritesfml

C++ SFML Frogger Sprite Movement


I am new to coding and currently making a C++ version of Frogger using SFML.

I want my frog to move like it does here: http://froggerclassic.appspot.com/

Currently I am using isKeyPressed to move my frog and it is moving in a smooth motion in any direction rather than jumping from position to position how I intend it to. How should I go about implementing this?


Solution

  • As often there are multiple solutions.

    You can use events instead of real-time inputs. That way you can move once when a KeyPressed event happens and don't move until the KeyRelease event happens.

    Alternatively, you can introduce a sort of cool down for your key. So when you detect a key press the first time you move the frog by X amount and staet the cooldown timer. As long as the timer isn't zero, you don't move the frog. As timet you can use an sf::Clock and a sf::Time.