Jump to content

[Solved] Looping Through An Animation Once


Shard
 Share

Recommended Posts

For our reloading animation, I need it to reload once per call, which means that it needs to play from its start frame of 0 to its end frame of 100 and then stop until the reload animation is called again.

 

So far, I haven't managed to figure out how to properly do the reload animation so that it starts and stops at the correct times.

 

The code I have below usually stops the animation at the right time, but sometimes it does it three or four times over before it stops. The animation also generally starts in the middle, around 30 or 40 and sometimes near the end like 95.

 

//Animation Code - Reloading Case


case reload:
	aniStart = weapon->reloadStart;
	aniEnd = weapon->reloadEnd;

	//DOF
	frameWork->GetRenderer().SetFarDOFRange(Vec2(0,50));
	frameWork->GetRenderer().SetFarDOFStrength(200);
	frameWork->GetRenderer().SetFarDOF( true );

	frame=AppTime()/30.0;

	frame=fmodf(frame,aniEnd-aniStart)+aniStart; 

	if(frame <= aniEnd-1)	
	{
		(bodyMesh,frame,1.0,0,true);
	}

              else wepState = idleUp;
              break;
}

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Hi Shard!

I think that in case of none loop animation you should calculate frame the other way:

 

frame=StartFrame
switch(state){

case reload:

frame+=ANIM_SPEED*Engine::GetSpeed();
Animate();
if (frame>=EndFrame)
state=anotherState;
break;

}

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

Hi Shard!

I think that in case of none loop animation you should calculate frame the other way:

 

frame=StartFrame
switch(state){

case reload:

frame+=ANIM_SPEED*Engine::GetSpeed();
Animate();
if (frame>=EndFrame)
state=anotherState;
break;

}

 

 

What is ANIM_SPEED?

And is GetSpeed the same as AppSpeed()?

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

one more way to calculate frame is calculate it based on animation speed in fps. For example you have animation that is made as 30 fps animation. Then frame will be:

 

frame+=30*(Engine::GetTime()-prevAnimTime)/1000.0;
Animate(frame);
prevAnimTime=Engine::GetTime();

 

Then your animation will always be played 30 frames per second.

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

one more way to calculate frame is calculate it based on animation speed in fps. For example you have animation that is made as 30 fps animation. Then frame will be:

 

frame+=30*(Engine::GetTime()-prevAnimTime)/1000.0;
Animate(frame);
prevAnimTime=Engine::GetTime();

 

Then your animation will always be played 30 frames per second.

 

 

Thank you very much. Your suggestions worked marvelously.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...