Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying a complete my method, which crops Maya-Animations (from Maya-Models) to specific ones using the SkinnedModelProcessor.

My only problem is, that after one animation-loop completes, the model stays in its last position for about 2-3 seconds until he catches up to the run-cycle again.

My goal is to get rid of that freeze time. I want to loop it seamlessly.

Here is what I wrote:

public AnimationClip getCurrentAnimation(string clipName, string cropName, float blendTime, int beginFrame, int endFrame, int totalFrames)
    //The new list which only has the specific keyframes
    List<Keyframe> region = new List<Keyframe>();

    //The original clip "Take 001" from Maya, which has every
    //animation in one timeline
    AnimationClip clip = _skinningData.AnimationClips[clipName];

    //The new duration of the cropped clip
    int duration = 0;

    //Since XNA makes 7502 frames out of 21, I have to 
    //calc the region-keyframes to proper numbers
    if (endFrame == 0)
        endFrame = clip.Keyframes.Count;
        endFrame = ((endFrame * clip.Keyframes.Count) / totalFrames);

        beginFrame = ((beginFrame * clip.Keyframes.Count) / totalFrames);

    //Start to sort out
        for (int i = beginFrame; i < endFrame; i += 1)
           Keyframe k = clip.Keyframes[i];

           //Add duration of 16 (60fps) to overall-length
           //of animation, if this keyframe does some "real" 
           //transformation, instead of being a static keyframe of XNA
           if (k.Time.Milliseconds > duration)
                duration += 16;

            k.Time = TimeSpan.FromMilliseconds(duration);

         AnimationClip cropped = new AnimationClip(cropName, TimeSpan.FromMilliseconds(duration), region);
         return cropped;
share|improve this question
What are you wanting to have instead of the freeze time? Loop the animation? Go back to default pose? What's stopping you from just switching to the next animation after a loop ends? – Byte56 Apr 22 '13 at 17:10
I am trying to loop the animation. It's a run cycle – IMX Apr 22 '13 at 17:41
For some reason, the start and the end of the loop don't match. That causes a non-fluid loop – IMX Apr 22 '13 at 17:55
So you either need to make the animations blend, or you need to create animations that end at the same pose they started in. Your question is asking about freezing animations, but you seem to know why it's freezing. Why aren't you asking about how to loop animations? – Byte56 Apr 22 '13 at 17:58
Well, that's pretty much what I asked – IMX Apr 22 '13 at 18:01

If you want seamless looping animations, create your animations so that the start of the loop is the same pose as the end of the loop. Then when one loop ends, you can simply start playing the second loop without needing to make any changes.

Alternatively, you can blend between the two animation poses. This is where you'll use your blendTime value. Spanning the amount of time defined in blendTime, use linear interpolation to blend between the last pose of the current animation and the first pose of the next animation.

share|improve this answer
One small, probably pointless, addendum: If the frames per second is low enough, ending on the same position as the loop starts will cause a noticeable hiccup in the animation. While most games run 30-60 fps, if anyone reading this answer is, for whatever reason, running their animation much slower, a slight adjustment will need to be made. – Attackfarm Apr 22 '13 at 18:30
@Attackfarm Indeed. I would suggest making the animations start and end on the same frame, but end the loop one frame early, so that it's next frame and the beginning frame are the same. – Byte56 Apr 22 '13 at 18:37
So you can ensure me, that the code above is correct? – IMX Apr 22 '13 at 18:38
Nope. I haven't read through it. I'm answering your question, not correcting your code. – Byte56 Apr 22 '13 at 18:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.