SFML community forums

Help => System => Topic started by: Jiggered on August 10, 2012, 03:52:55 pm

Title: Applying clock to movements
Post by: Jiggered on August 10, 2012, 03:52:55 pm
In my game app I have moving sprites, but without them being tied to a clock they just fly across the screen. So I need help fixing my clock code so that my sprites move with the clock timer.

                 Sprite.Move(-1 * elapsedTime ,0);
                 if(elapsedTime>REFRESH_RATE){
                        // get current system time
                        GetSystemTime(&st);
                         if(Sprite.GetPosition().x <= 50)
                                 {
                                        Sprite.Move(0, 10 * elapsedTime);
                                 } else if (Sprite.GetPosition().y == 60)
                                 {
                                         Sprite.Move(1 * elapsedTime,0);
                                 }
                        Clock.Reset();
                }
Title: Re: Applying clock to movements
Post by: Nexus on August 10, 2012, 06:27:44 pm
What is your problem? Do you have a minimal and complete example?

And why do you mix sf::Clock with GetSystemTime()?
Title: Re: Applying clock to movements
Post by: Jiggered on August 24, 2012, 06:20:13 am
The problem I am having is that I'm trying to make a sprite move across the screen, the movement of the sprite works fine, but without applying timesteps to make it move on every second (or whatever I set the timestep to) it just zooms across at full speed.

I don't have any other example, and I mixed them because I thought they were meant to go together, I guess not.
Title: Re: Applying clock to movements
Post by: eXpl0it3r on August 24, 2012, 07:35:30 am
You can find there (http://en.sfml-dev.org/forums/index.php?topic=8942.msg60227#msg60227) an example of a framrate based movement.
Title: Re: Applying clock to movements
Post by: Jiggered on August 24, 2012, 02:30:59 pm
I looked through the example and that won't work for me because I'm using SFML 1.6. I tried re-writing it for 1.6 and I couldn't get it to work.

Are there any other solutions?
Title: Re: Applying clock to movements
Post by: victorlevasseur on August 24, 2012, 03:10:40 pm
Use SFML 2.0 RC ?
Title: Re: Applying clock to movements
Post by: eXpl0it3r on August 24, 2012, 08:11:42 pm
Use SFML 2.0 RC ?
Yes definitely! SFML 2 is way better than the 1.6 version.

Well most of the stuff is the same from 2.0 to 1.6, you can take a look at the official tutorials to understand how things work with SFML 1.6 (since you kind of do some strange things in that provided code snippet).
The only two 'bigger' differences are that sf::Keyboard has to be replaced with the sf::Input class (see tutorial) and that sf::Clock doesn't return a sf::Time object but a float.
Both documentations are online and you'll find all the needed symbols and names there. ;)