SFML community forums

Help => Graphics => Topic started by: TheDianamu on September 15, 2013, 08:09:49 am

Title: sf::Keyboard Only move the Sprite in the direction once
Post by: TheDianamu on September 15, 2013, 08:09:49 am
Hi, I'm working on a game and I'm stuck on Movement

I have the following code in my main.cpp

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) sprite.move(-20,0);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) sprite.move(20,0);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) sprite.move(0,-20);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) sprite.move(0,20);
 

Im just trying to figure out, why it isn't allowing me to move the sprite continually. Would I need to do something like
float speed = 5.f;
?

Thanks in advance.


Title: Re: sf::Keyboard Only move the Sprite in the direction once
Post by: Laurent on September 15, 2013, 09:06:27 am
Quote
Im just trying to figure out, why it isn't allowing me to move the sprite continually
Because something is wrong in your code. So show it ;)