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

Author Topic: Clock::GetElapsedTime () in milliseconds  (Read 5369 times)

0 Members and 1 Guest are viewing this topic.

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Clock::GetElapsedTime () in milliseconds
« on: May 10, 2011, 10:05:57 pm »
Clock::GetElapsedTime () returns the time in seconds. I think this is way too
coarse grained, when i call (and reset) this every frame, it always returns 0.
No wonder, my machine can draw more than one frame per second...

I think the method should return the elapsed time in milliseconds.

The reason is, i want to use the clock to animate my objects. In a simple
example, when my objects just moves straight with a given speed, i can
determine its new position, given the time passed by since the last frame.
That does'nt work however, if the time passed is always 0.

My guess is, other people had the same problem, how did you solve it?

And out of couriosity: What is the purpose of a clock with seconds granularity?

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Clock::GetElapsedTime () in milliseconds
« Reply #1 on: May 10, 2011, 10:35:16 pm »
Nevermind, i wasn't paying enough attention. The return value is a float.
But i became an int, when i passed it down in my app. A float is perfectly fine.

PhiLLe

  • Newbie
  • *
  • Posts: 36
    • View Profile
Clock::GetElapsedTime () in milliseconds
« Reply #2 on: May 10, 2011, 10:35:16 pm »
The definition is:
Quote
float sf::Clock::GetElapsedTime()


I am sure you are doing this:
Code: [Select]
int a = clock.GetElapsedTime();
This int just holds seconds since the return value is rounded.

Try this:
Code: [Select]
float a = clock.GetElapsedTime();

Edit: too late..

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Clock::GetElapsedTime () in milliseconds
« Reply #3 on: May 10, 2011, 10:41:39 pm »
Exactly, i did something like this. Cheers...