Sign in to follow this  

How can I play an animation only once?

This topic is 3726 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, I've made two animations.One is called "walk",and the other is "jump",they are in the same .X file. Frame 94-124:walk, Frame 178-203:jump. Here is the problem i've got.I want my hero(in my game) to jump when I press the space key,and need it to jump only once,then translate to "walk" automatically. I've been thinking about using the ID3DXAnimationCallbackHandler interface.I set a key at the end of the "jump" animation to notice my ID3DXAnimationController to chang the animationset to "walk".But I still have the "walk" animation to deal with, and it needs two keys to play the step sound at proper time. So,I guess it's not the best way to do this,since it costs to change the keys frequently. The most import thing is that it looks like too inconvenient.I gess there should be a more effiect and direct way. Then I found ID3DXAnimationController::GetTime() method in SDK,which is used to gets "the global animation time". Is this used to get the current time of the whole animation's duration?If yes, how can i get the duration of "jump".If I get both the current time and the whole duration,I can figure out the percent of the animation being played,when which reach to 100%,I can chang the animationset to "walk". So,is there anyone familiar with animation controlling.Help me please!

Share this post


Link to post
Share on other sites
IMO, you'll be better off if you split the two animations into their own animation sets instead of having them be two portions of the same animation.

That way you don't have to rely on weird magic number effects in order to play one animation, or the other.

Share this post


Link to post
Share on other sites
Thanks for your advice!
But I don't quite catch you.Would you please tell me how to
divide one animation into two?
Actually ,I guess I have divided them. The .X file was
exported by Panda plugin for 3ds max9. And the two animations are in different frame sections,"walk" 94-124,and "jump" 178-203.
In my codes I switch between them like this:


LPD3DXANIMATIONSET pAnimationSet;

if(m_PlayerList[i].m_Action == csChar::ACTION::walk)
{
if(FAILED(m_animCtrl->GetAnimationSetByName("walk",&pAnimationSet))) return E_FAIL;
}
else
{
if(FAILED(m_animCtrl->GetAnimationSetByName("jump",&pAnimationSet))) return E_FAIL;
}
if(FAILED(m_animCtrl->SetTrackAnimationSet(0,pAnimationSet))) return E_FAIL;



And the most concerned question is that how to know that the "jump" animation is
played for only once?Is there a method to get the progress of the animation?
Thanks again!

ps:How to post my codes in a single text controller?:)

Share this post


Link to post
Share on other sites
same as legalize, I also suggest you to sprite animation in to 2

the meaning is

.X file can contain more than 1 animation set on each object

so your hero can contain 2 animation
1. is jump start from frame 1 to N
2. is walk start from frame 1 to N

and more and more animation

I'm not sure how to set DDX to play each animation set (I'm using OpenGL). but I quite sure that DDX can (because .X is dedicate for DDX)

Chet Chetchaiyan

Share this post


Link to post
Share on other sites

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