Hey there people,
I'm creating a very simple Mario clone for myself and i'm trying to create a smooth movement for Mario, I'm using C++ and SFML for this project,
This is the code I have at the moment
void State::KeyboardEvent(sf::Event event)
{
if (state == GameStates::GS_Level1)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
//Set move right to true
Characters.at(0).UpdateMovement(2, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
//Set move left to true
Characters.at(0).UpdateMovement(-2, 0);
}
}
}
This works but not smoothly at all, when the D or A key is pressed down, Mario will move once, then he will continue after about a second delay, it's like holding key down on your keyboard, it will type a letter, but if you keep it held down it will repeat that character, I'm thinking the best way is to maybe set a state, so if A key is pressed set mario state to moving left, and when a is released change the state to stopmoving and once speed is 0 set state to not moving, but i can't really find a good site explaining this and was hoping for some help from your guys,
Any idea on how I should implement this?