Jump to content

Performing an Animation Loop with just one frame


darrenc182
 Share

Recommended Posts

I am trying to animate a character after he dies using the last frame of a death sequence. I cannot get this to work at all. I have some simple code to do this but it looks like the character just sits there at the first frame of animation of the idle sequence.

 

flt next_frame = 575.0f;

next_frame = (AppTime() - animationStartTime) / frameSpeed;
next_frame = fmod(next_frame, 575 - 578) + 575;

Animate(m_Entity, next_frame, 1, 0, true);

 

What happens with the code above is that the animation seems to flip from the last frame of the death sequence to the first frame of the idle sequence. Is there any way to feed the Animate function just one frame and have it position the character?

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

Link to comment
Share on other sites

Why not just stop animating altogether?

 

How do I get the character rendered at that frame? I tried using no recursion during the entire death sequence but the animation doesn't play at all when I do that.

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

Link to comment
Share on other sites

I cannot get the animation to play with no recursion. I'm thinking that there is something wrong with the Animate function.

 

Update:

 

I wrote a simple program to try and isolate the problem. I can get the animation to work when the recursion parameter is 1 but not when it is 0.

 

Here is my code in its entirety:

 

#include "engine.h"
#include "Framewerk.h"

leadwerks::Framewerk fw;
TModel swat_officer;

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
flt next_frame, animationStartTime;

if(!Initialize())
	return 0;

RegisterAbstractPath("I:\\Leadwerks\\LEAnimationTest\\LEAnimationTest\\Data");

//Create a graphics context	
Graphics(800, 600);

if( !fw.Create() )
{
	MessageBoxA(0,"Failed to initialize engine.",NULL,0);
	return 1;
}

fw.SetStats(0);

fw.GetRenderer().SetSSAO( false );
fw.GetRenderer().SetBloom( false );

fw.GetRenderer().SetDistanceFog(false);
fw.GetRenderer().SetGodRays(false);
fw.GetRenderer().SetHDR(false);

AmbientLight(Vec3(0.7f, 0.7f, 0.7f));

PositionEntity(fw.GetMain().GetCamera(), Vec3(0.0f, 0.0f, -250.0f));
swat_officer = LoadModel("abstract::swat_officer.gmf");
PositionEntity(swat_officer, Vec3(0.0f, -75.0f, 10.0f));

animationStartTime = AppTime();

while(!KeyHit())
{		
	UpdateWorld(AppSpeed());

	fw.Update();
	fw.Render();

	fw.GetMain().SetWorld();

	next_frame = (AppTime() - animationStartTime) / 30.0f;
	next_frame = fmod(next_frame, 1 - 200) + 1;

	Animate(swat_officer, next_frame, 1, 0, 0);

	Flip();
}

return 1;
}

 

I am using Leadwerks Engine 2.31.

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

Link to comment
Share on other sites

Alright I got it working. I had to rework my animation management code. The code below will animate a sequence (in this case a death animation sequence) and at the end of the animation it will stay on the last frame of the animation.

 

next_frame = (AppTime() - animationStartTime) / 30.0f;
next_frame = fmod(next_frame, 575-540) + 540;

if(next_frame > fCurrentFrame)
fCurrentFrame = next_frame;
else {
bNextSequence = true;
next_frame = (AppTime() - animationStartTime) / 30.0f;
next_frame = fmod(next_frame, 1) + 575;
fCurrentFrame = next_frame;
}

Animate(swat_officer, fCurrentFrame, 1, 0, 1);

 

Hopefully this helps anyone else that needs help with this.

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

Link to comment
Share on other sites

I think what Josh is saying is if a character is dead, don't call the Animate() method anymore once the death animation plays out to the end. The character should stay at whatever the last animation frame was without making calls the Animate() once they are dead. What you seem to be doing is stopping the frame of the animation on the last frame of the death animation and continue calling Animate() with that last frame every cycle. There is no need to do that once you know you have reached the last frame. Just make a boolean that tells if the character is alive or not. Set it to true when the last frame of the death animation is reached and then put an if check on the 'alive' boolean around the Animate() method to skip calling it when the character is dead.

Link to comment
Share on other sites

OK you guys are right. I set it up to no longer animate after the last frame of the death sequence. I did try this before, but I think the parameters I was using for the death sequence were not correct which was creating the incorrect results.

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

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...