# Play an animation ONCE with directX

## Recommended Posts

Here's the problem! I'm using a animated mesh with directx functions and stuff. I can play different animations over and over again but i haven't figured out how to just play an animations for just one time.

I've tried this:
LPD3DXANIMATIONSET temp = NULL;if(AniController->GetAnimationSetByName(AnimationName, &temp) != S_OK)    return;AniController->SetTrackAnimationSet(Track, temp);AniController->SetTrackEnable(Track, true);AniController->SetTrackSpeed(Track, 1.0f);AniController->SetTrackWeight(Track, 1.0f);AniController->ResetTime();AniController->KeyTrackEnable(Track, false, temp->GetPeriod());temp->Release();

But the animation just ends after a random time. I've checked the temp->GetPeriod() value and it's the same everytime.

Am I approaching it all wrong? or Am i just doing it wrong?

##### Share on other sites
First, every DirectX function gives some indication of success or failure. You don't check for errors in any (except the first) of your AniController calls.

Are you using the Debug Runtime? Does it tell you anything?

What do you mean by "random" time? Is it always a different length of time or is it consistent but appears incorrect?

In the way of debugging, have you tried setting KeyTrackEnable to other times?

Does it behave the same way for different animation sets?

Does it always stop after the same length of time, even for different animation sets?

##### Share on other sites
I've checked if all of the functions succeeds and they do. I've manually set the time of KeyTrackEnable and it didn't work. It seems the animation starts playing at random keyframe. Same thing with other animations

##### Share on other sites
SOLVED :D

I used the SetTrackPosition() and set it to Zero and it works perfectly!
But if someone knows why this happend then please give a explanation :)

##### Share on other sites
Quote:
 I used the SetTrackPosition() and set it to Zero

Your KeyTrackEnable call stops the animation after the track time reaches the animation set period. If the track position isn't at zero when you set the new animation, it still stops at that value.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627675
• Total Posts
2978572

• 11
• 11
• 10
• 12
• 22