Skip to main content
gamedev.net
🔒 Locked

Time Based Animation

Started by Neen10do Apr 26, 2003 at 11:43 PM 5 replies 550+ views
Original Post
Neen10do
Neen10do
im trying to make my animation for my cObject class (2d), and because i want the animations to run at about the same speed on every computer, im going to need to do the animation frames based on time, not framerate. so here is my advanceframe code for my animation class:
    
//Advance Frame/////////////////

void cAnimation::AdvanceFrame(DWORD TimeDelta)
{
	//Adds up Elapsed time

	ElapsedTime += TimeDelta;

	//Tests for next frame

	if(ElapsedTime >= AnimationSpeed)
	{
		ElapsedTime = 0;
		//Advances Frame

		myXCell++;
                if(myXCell >= numCols)
                     myXCell = 0;
	}
}
////////////////////////////////

    
my question is, is this the right way to go about it? TimeDelta is the time between two frames. i thought of this and couldn't think of any more obvious solution. any input would be great. thanks. ---------------------- i code therefore i am. Aero DX - Coming to a bored Monitor near you! [edited by - Neen10do on April 27, 2003 1:33:30 AM]
----------------------i code therefore i am.Aero DX - Coming to a bored Monitor near you!
Neen10do
Neen10do
anyone?


----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!
----------------------i code therefore i am.Aero DX - Coming to a bored Monitor near you!
Kyo
Kyo
I just use

//initialize function
timeCounter = GetTickCount();


//update animation function
if (GetTickCount() - timeCounter > animationTime)
{
timeCounter = GetTickCount();
//change animation frame
}
Rob Loach
Rob Loach
Use the difference in time between frames to move objects.

Player.x += Player.Velocity * DiffTime

Also use milliseconds because then it moves it makes it the velocity units (pixels) per second.

[EDIT] Oh! Sprite Animation. I used DiffTime as well, but had another timer to indicate when the next sprite frame was.


- Rob Loach
Current Project: Upgrade to .NET and DirectX 9

"Do or do not. There is no try."
- Yoda

[edited by - Rob Loach on April 27, 2003 12:31:10 PM]
Rob Loach [Website] [Projects] [
deadalive
deadalive
I'm using this approach, but my program seems to "jump" on crappy systems. Is this normal? Is there a way to adjust it for a crappy PC? My pentium4/2.0Ghz with a GeForce3Ti runs it so perfectly, but on my pentium2 with a Riva TNT card, it looks bad. Something tells me that is bad timer code..

Is there a library to handle this time based motion garbage more easily? Everywhere I look people are complaining about this or don't understand it, it seems simple but to a beginner it sure isn't.



[edited by - deadalive on April 28, 2003 2:16:04 PM]
this place is lame
quack
quack
Your routine looks fine but it might not work right if the delta is greater than 2 times the animationSpeed. The frame would only advance once instead of how ever many times it really should. Like if time delta is 3 seconds and the anim delay is 1 second it should skip 2 frames, but how you have it it won't. That might be the problem. So you might want to take a look at that and figure something out.


[edited by - quack on April 28, 2003 4:27:15 PM]
www.autodefrost.com/~travisSignature Virus cleaned by McAfee
Neen10do
Neen10do
well i was thinking about that, and thought that maybe a slow down for a quick second might be a little less noticable than a skip in frame, it depends.

the AnimationSpeed for one of my objects is 60 msec, meaning that the time changed would have to be 120msec, lets do a little simple math:

1000/120 = 8 1/3;

aka, their computer sucks if they only get 8 frames a second, and should be destroyed immediately.

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!
----------------------i code therefore i am.Aero DX - Coming to a bored Monitor near you!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.