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

Author Topic: Tutorial question  (Read 3397 times)

0 Members and 1 Guest are viewing this topic.

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Tutorial question
« on: August 30, 2009, 03:56:14 am »
In the 1.5 tutorials named "Displaying a sprite" they say to use a clock to make movement the same across different computers. In the tutorial they use GetElapsedTime()... my question is shouldnt they be calling the Reset() function after every cycle, otherwise it will always speed up because the timer is never being reset. Just wondering about that because I couldnt get a lot of my unit movement correct and then I put a call to Reset() and everything works =O

Edit: I just noticed they had a call to reset in the other tutorial that went over time. Whoever made the tutorial on "Displaying a sprite" forgot to add a call to Reset()
Eugene Alfonso
GTP | Twitter

Meltra Bour

  • Newbie
  • *
  • Posts: 28
    • View Profile
Tutorial question
« Reply #1 on: August 30, 2009, 09:16:14 am »
Duno but the tutorial I'm looking at doesn't use GetElapsedTime() or a clock ...
http://www.sfml-dev.org/tutorials/1.5/graphics-sprite.php ??

it uses sf::RenderWindow::GetFrameTime(), a special clock that returns the time elapsed since last frame, it resets every time a frame ends.

But yha I still agree that this isn't the way to get consistent movement.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Tutorial question
« Reply #2 on: August 30, 2009, 09:55:33 am »
Quote
But yha I still agree that this isn't the way to get consistent movement.

Why?
Laurent Gomila - SFML developer

Meltra Bour

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Tutorial question
« Reply #3 on: August 30, 2009, 10:35:43 am »
Quote from: "phear-"
they say to use a clock to make movement the same across different computers


GetFrameTime() is a *clock* but the result will be different depending on computers speed, so you would need a other variable/check to make sure different commuters animate at the same speed. Using a real clock you can make it more accurate with less math, then again maybe it's just me or the way you implement it.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Tutorial question
« Reply #4 on: August 30, 2009, 07:26:34 pm »
Quote from: "Meltra Bour"
GetFrameTime() is a *clock* but the result will be different depending on computers speed

Which is exactly what you want, isn't it? The faster a computer renders a frame, the fewer movement happens -- and vice-versa.

You can use GetFrameTime() as a factor. For example, if the target FPS is 60, you can get a factor by calculating GetFrameTime() * 60, so that you get a factor of 1 when rendering with 60 FPS. When the FPS drops below 60, the factor will be greater than 1, so movements will be faster.

 

anything