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

Author Topic: Need help making a shape move automatically  (Read 1679 times)

0 Members and 1 Guest are viewing this topic.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
Need help making a shape move automatically
« on: May 19, 2011, 10:52:13 am »
Hello, i am new to SFML and i wanna just do a simple program where u press an arrow key and the ball moves in the direction until you press space bar, i know in visual basic you can get timers which do this very easily (shape.left = shape.left + 1) can u make a timer function in SFML and it constantly does the action like in Visual Basic

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Need help making a shape move automatically
« Reply #1 on: May 19, 2011, 04:16:55 pm »
This shouldn't be done with timers.

In game programming you typically have a loop which drives all logic.  It usually looks something like this:

Code: [Select]

while( game_is_running )
{
    ProcessEvents();

    UpdateWorld();

    DrawWorld();
}


You would then updates all objects in your 'UpdateWorld' function.  So you could call
Code: [Select]
yourball.Update(); which would move it in whatever direction it's going.

 

anything