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

Author Topic: Applying clock to movements  (Read 6322 times)

0 Members and 1 Guest are viewing this topic.

Jiggered

  • Newbie
  • *
  • Posts: 9
    • View Profile
Applying clock to movements
« 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();
                }

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Applying clock to movements
« Reply #1 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()?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jiggered

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Applying clock to movements
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Applying clock to movements
« Reply #3 on: August 24, 2012, 07:35:30 am »
You can find there an example of a framrate based movement.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jiggered

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Applying clock to movements
« Reply #4 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?

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Applying clock to movements
« Reply #5 on: August 24, 2012, 03:10:40 pm »
Use SFML 2.0 RC ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Applying clock to movements
« Reply #6 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything