Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Keyboard Only move the Sprite in the direction once  (Read 1009 times)

0 Members and 1 Guest are viewing this topic.

TheDianamu

  • Newbie
  • *
  • Posts: 20
    • View Profile
sf::Keyboard Only move the Sprite in the direction once
« 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.



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Keyboard Only move the Sprite in the direction once
« Reply #1 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 ;)
Laurent Gomila - SFML developer

 

anything