This is my first post in the forums. I'm a total C++ noob, but I've watched all the beginner series videos, and I wanted to first thank Chili for providing such awesome content.
I've been toying around with sprite animation and I had a question regarding the method we used in Lessons 20 and 21 regarding the variable currentFrameExposure in our UpdateAnimation function. My understanding is that we use currentFrameExposure to force the program to go through a loop a certain number of times before updating to the next animation frame. The amount of time is based on the speed at which the computer goes through the loop, which will vary from machine to machine. I am looking for a way to update animation smoothly based on a time between animation frames that will remain constant no matter the computer. I've toyed around with Sleep(); but have had limited success. Is there something specific I should be doing here? Am I understanding currentFrameExposure correctly?
Thanks for any help,
Ryan
Question re UpdateAnimation and currentFrameExposure
- ryanbowles42
- Posts: 3
- Joined: January 25th, 2013, 7:25 pm
Re: Question re UpdateAnimation and currentFrameExposure
Yeah that's exactly what happens. What i did was use Chili's Timer class to get time passed per frame in seconds.
Edit: I realized my addition to the timer class was unnecessary.
Just add this function to the Timer class.
Now you can get how much time has passed per frame in seconds. Create a Timer object and also a time variable in the Game class.
Add this to the bottom of Game's Go() function to get the time passed in seconds.
All you have to do now is, whenever you have something that moves a certain distance just multiply it by "time". for example:
This will move to the right at 10 pixels per second, no matter what computer its on.
Edit2: I forgot you were talking about changing frames, not movement .
Edit: I realized my addition to the timer class was unnecessary.
Just add this function to the Timer class.
Code: Select all
float Timer::GetTimeSec() const
{
if( !watchStopped )
{
QueryPerformanceCounter( (LARGE_INTEGER*)¤tCount );
return ((float)(currentCount - startCount) * invFreqMilli) / 1000;
}
else
{
return ((float)(currentCount - startCount) * invFreqMilli) / 1000;
}
}
Code: Select all
Timer timer;
float time;
Code: Select all
timer.StopWatch();
time = timer.GetTimeSec();
timer.StartWatch();
Code: Select all
if( kbd.RightIsPressed() )
{
x += 10 * time;
}
Edit2: I forgot you were talking about changing frames, not movement .
Last edited by Musi on January 27th, 2013, 9:07 pm, edited 3 times in total.
Musi
There are 10 types of people that understand binary.
Those that do, and those that don't.
There are 10 types of people that understand binary.
Those that do, and those that don't.
- ryanbowles42
- Posts: 3
- Joined: January 25th, 2013, 7:25 pm
Re: Question re UpdateAnimation and currentFrameExposure
Thanks for the reply, I'll try implementing the timer class in my code.
Re: Question re UpdateAnimation and currentFrameExposure
wow,
good to know..
..same problem here. My games look very different from when they are being used on other machines. my laptop is so slow.. 40 per sec
good to know..
..same problem here. My games look very different from when they are being used on other machines. my laptop is so slow.. 40 per sec
Re: Question re UpdateAnimation and currentFrameExposure
Here is a great article on game loop. Pretty good explained and outlining pluses vs. minuses of each implementation.
- ryanbowles42
- Posts: 3
- Joined: January 25th, 2013, 7:25 pm
Re: Question re UpdateAnimation and currentFrameExposure
Indus, I was able to get my animation working as intended using information in that article, thanks for the link.