Jump to content
  • Advertisement
Sign in to follow this  
Lith

Weired SFML Clock Problems

This topic is 2541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

I am making an animation class to use in my game that, when asked, will give the frame of animation that the object needs to be on. You can do something like this:


Animation TestAnimation;
GameObject TestGameObject;

TestAnimation.Create(2,4); // 2 seconds for each frame and 4 frames in total
TestAnimation.Start();

// In the main loop somewhere...

TestGameObject.Draw(TestAnimation.GetFrame());



The problem i have resides in the GetFrame function:



if(running)
{
float timeElapsed = mainClock.GetElapsedTime();
float framesPassed = timeElapsed / timeForEachFrame;
int curFrame = currentFrame + (int)framesPassed;

if(curFrame > numberOfFrames)
{
currentFrame = curFrame % numberOfFrames;
}
else
{
currentFrame = curFrame;
}

return currentFrame;
}
else
{
return 0;
}


The function was returning 0 for about 2 to 3 seconds and then would seem to spit out random numbers between and including 0 to the total frame number. I did some investigation and found out that the number i got from mainClock.GetElapsedTime() was suddenly increasing by 3 to 10 when the function stopped returning 0.

Is this a bug in sfml or am i doing something stupid?

Share this post


Link to post
Share on other sites
Advertisement
[font="arial, verdana, tahoma, sans-serif"]

Are you calling mainClock.Reset() anywhere?


I was only calling it in the Start() function:



void Animation::Start()
{
running = true;
mainClock.Reset();
}


I added this code to the function and made it work!


int oldCurrentFrame = currentFrame;

// functions goes here...


if(oldCurrentFrame != currentFrame)
{
mainClock.Reset();
}

return currentFrame;

[/font]

Is this a bug in sfml or am i doing something stupid?


I was doing something stupid...
Anyway, thanks for your help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!