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

Author Topic: Moving Objects  (Read 10768 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Moving Objects
« 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?

coral

  • Newbie
  • *
  • Posts: 37
    • View Profile
Moving Objects
« Reply #1 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!

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Moving Objects
« Reply #2 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);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Moving Objects
« Reply #3 on: September 23, 2008, 07:07:29 pm »
Probably because you didn't read the tutorial ;)
Laurent Gomila - SFML developer

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Moving Objects
« Reply #4 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();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Moving Objects
« Reply #5 on: September 23, 2008, 07:20:07 pm »
Laurent Gomila - SFML developer