Sign in to follow this  

Having Trouble Detecting The End Of A Animation

This topic is 1262 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

Hi All.
I would like to have my update Animation function return true when the animation is at the end.
I have in my animation update function where it detects the last frame time, It was working on a larger animation
but I am trying it on a animation that has 30 frames and its max time is 4800(last frame time).

I steped through the code and my frame delta time value passed into this function is like 3200000 thats a big number

if I loop the animation it runs fine. even with this larg time value, Another thing if I break the code before the update animation function
the frame delta is 103.1 so some where in passing and entering the function funky stuff is happening. I thought it came from passing a float to a windows FLOAT
So I changed the FLOATS to float but the same thing.????

Maybe its because my animation time is a DWORD and my timer class is a double casted to a float for time deleta. What should I do here????

Ok heres some code the first is the UpDateAnimation function and the next is the timer class I'm using.

void AnimationCollection::Update(char *AnimationSetName,     
                                  DWORD Time, BOOL Loop, BOOL *atend)
  cAnimationSet *AnimSet = m_AnimationSets;

  //set atend to false;
  if(atend)//if its being used
*atend = false;

  // Look for matching animation set name if used

   // Find matching animation set name
   while(AnimSet != NULL) 

    // Break when match found
    if(!_stricmp(AnimSet->m_Name.c_str(), AnimationSetName))

   // Go to next animation set object
   AnimSet = AnimSet->m_Next;

  // Return no set found
  if(AnimSet == NULL)

  // Bounds time to animation length
  if(Time >= AnimSet->m_Length)
//if atend is not null we can see if we are looping if we are then we dont get to the end
//but if loop = false we set it to true
     *atend = FALSE;
     *atend = TRUE;
Time = (Loop==TRUE)?Time%(AnimSet->m_Length+1):AnimSet->m_Length;

timer class

class GameTimer

	float getGameTime(void)const;  // in seconds
	float getDeltaTime(void)const; // in seconds

	void reset(void); // Call before message loop.
	void start(void); // Call when unpaused.
	void stop(void);  // Call when paused.
	void tick(void);  // Call every frame.

	double mSecondsPerCount;
	double mDeltaTime;

	__int64 mBaseTime;
	__int64 mPausedTime;
	__int64 mStopTime;
	__int64 mPrevTime;
	__int64 mCurrTime;

	bool mStopped;

float GameTimer::getDeltaTime(void)const
	return (float)mDeltaTime;

void GameTimer::tick(void)
	if( mStopped )
		mDeltaTime = 0.0;

	__int64 currTime;
	mCurrTime = currTime;

	// Time difference between this frame and the previous.
	mDeltaTime = (mCurrTime - mPrevTime)*mSecondsPerCount;

	// Prepare for next frame.
	mPrevTime = mCurrTime;

	// Force nonnegative.  The DXSDK's CDXUTTimer mentions that if the 
	// processor goes into a power save mode or we get shuffled to another
	// processor, then mDeltaTime can be negative.
	if(mDeltaTime < 0.0)
		mDeltaTime = 0.0;

Share this post

Link to post
Share on other sites

First: unless you intentionally want very large delta-times after you pause/un-pause the app, always update the current and previous times. Just set mDeltaTime = 0 when your app is paused after you've calculated mDeltaTime. Your code as posted will result in large deltas after a pause.


Second: when you're debugging (i.e., setting breakpoints), the clock will continue to run while you're staring at your code. While you're debugging, set mDeltaTime to a fixed value (something like 0.01667 - 60th of second). Then, when you want to run "live" (with the First suggestion above implemented), try things out with a "live" delta time.


EDIT: That is, your comment

// Time difference between this frame and the previous.

should read:

// Time difference since the last time the app was not in a stopped condition. May be 100s of seconds.
Edited by Buckeye

Share this post

Link to post
Share on other sites

Hey thanks.


What I have worked out is the elapsed time is ok for a looping animation as the time gets lapped to start frame.

But for a animation that you want to run once I need to keep the start time and use this time to calculate the frame like this.

I'm also now using timeGetTime() it should be more then enough for animation hey.??? as my Animation class uses DWORD for time anyway.


after 8 years this is the firts time i've wanted or needed a animation to play once lol hehehe.

I noraly just not animate them and only animate them when needed.


static DWORD StartTime = timeGetTime();//this was my test. StartTime is now part of the object

DWORD elapsed = (timeGetTime() - StartTime) *10;//the 10 speeds it up some


then when I want to play the animation again I set StartTime = timeGetTime(); and a flag that triggers the render to render the animation or its not called.


What I'm using it for is my SpearOfObjectPlacement it allows the user to place objects from the menu to the terrain with a left click.

this is where I play the the animation on the leftclick, then the spear raises a bit and slams into the terrain with some effects(next part) when the last frame is played.


Thanks Again All.

Share this post

Link to post
Share on other sites

This topic is 1262 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this