SFML community forums

Help => Graphics => Topic started by: ravenheart on September 22, 2008, 07:10:28 pm

Title: Moving Objects
Post by: ravenheart on September 22, 2008, 07:10:28 pm
Hi i want a shape to move when up / down is pressed


Code: [Select]

if ((Event.Type == Event.KeyPressed) && (Event.Key.Code == Key::Up))
        {
            Polygon.Move(0,-5);
            //Polygon.Rotate(15);
        }
        if ((Event.Type == Event.KeyPressed) && (Event.Key.Code == Key::Down))
        {
            Polygon.Move(0,5);
            //Polygon.Rotate(15);
        }


but it flickers how can i make it move smoothly?
Title: Moving Objects
Post by: coral on September 22, 2008, 07:48:22 pm
Read the tutorial, use the predefined functions like this to set a bool:

    bool         LeftKeyDown     = Input.IsKeyDown(sf::Key::Left);
    bool         RightKeyDown     = Input.IsKeyDown(sf::Key::Right);
    bool         UpKeyDown     = Input.IsKeyDown(sf::Key::Up);
    bool         DownKeyDown     = Input.IsKeyDown(sf::Key::Down);

Then check against the bools instead!
Title: Moving Objects
Post by: ravenheart on September 23, 2008, 06:54:10 pm
why doesnt that work:

Input i;
bool down = i.IsKeyDown(Key::Down) ;

        if(down)
            Polygon.Move(0,-10);
Title: Moving Objects
Post by: Laurent on September 23, 2008, 07:07:29 pm
Probably because you didn't read the tutorial ;)
Title: Moving Objects
Post by: ravenheart on September 23, 2008, 07:17:08 pm
what tutorial are u talking about i cant find it

is this missing?
const sf::Input& Input = App.GetInput();
Title: Moving Objects
Post by: Laurent on September 23, 2008, 07:20:07 pm
This one :
http://www.sfml-dev.org/tutorials/1.3/window-events.php