Recreation Creation with XNA/Arithmetic Physics/Character Animation

Game Creation with XNA/Mathematics Physics/Character Animation

Character Animation[edit]

Right here now we have to differentiate between skeletal and keyframed animation. The primary level is to indicate find out how to get each sorts of animation working with XNA. Particular consideration must be locations on contraints given by the XNA framework (e.g. the shader 2.Zero mannequin doesn’t permit greater than 59 joints).


Animation is simply an illusion- it’s created by a sequence of pictures. Every is a bit totally different from the final. We simply really feel such a bunch of pictures as a altering scene.
The most typical technique of presenting animation is as a movement image or video program, though there are different strategies. [1]
In Laptop based mostly animation there are two types of it: The little extra “classical”, from flip-books identified keyframe animation and the skeletal animation, which is by default identified from 3d-animation.

Keyframed Animation[edit]

Keyframe animation is an animation method, that originially was utilized in classical cartoons.
A Keyframe defines the start- and endpoint of an animation. they’re full of so known as interframes or inbetweens.

Historical past, Tradional Keyframe Animation[edit]

Within the traditioal keyframe animation, which e.g. was used for hand-drawn trickfilms, the senior artist (or key artist) would draw the keyframes. (Simply the vital photos of an animation)
After testing of the tough animation, he offers this to his assistand, and the assistand does the required “inbetweens and the clear up.


In Computergraphics it’s the identical idea like in cartoon: The keyframes are created by the consumer and the interframes are supplemented by the pc.
The “Keyframe” saves parameters similar to place, rotation and scale of an object
The next inbetweens are interpolated by the pc.


An Object will transfer from one nook to an different.
The primary keyframe reveals the item within the high left nook and the second keyframe reveals it within the backside proper nook. Every part in between is interpolated.

Interpolation strategies[edit]

The previous sections talked about that some key-frame animations assist a number of interpolation strategies. An animation’s interpolation describes how an animation transitions between values over its period. By deciding on which key body sort you employ along with your animation, you may outline the interpolation technique for that key body section. There are three several types of interpolation strategies: linear, discrete, and splined.



The person segments are go with fixed pace.


With discrete interpolation, the animation perform jumps from one worth to the subsequent with out interpolation.

Spline Interpolation[edit]

Figure 1: Interpolation with cubic splines between eight points. Making traditional hand-drawn technical drawings for ship-building etc flexible rulers were bent to follow pre-defined points (the

Keyframe Animation in XNA[edit]

to be edited
die einzelnen Parameter werden in einer Liste gespeichert.
Wenn man nun die Länge der Timeline und die anzahl der elemente hat, kann man hier draus schließen, auf welchen Keyframe man zu welcher Zeit zugreifen kann. (in dem der Timeline- Zähler hochgezählt wird und dann der entsprechende keyframe aufgerufen wird, ist es, als ob man z.b. bei einem daumenkino, bei dem 1 seite 1 keyframe ist, auf die enstsprechende Seite blättern würde).

Folgend ist eine klasse dargestellt, mit welcher dies umgesetzt werden kann. Die Quelle ist hier drunter zu finden.

Just a little keyframe animation class

utilizing System.Collections.Generic;
utilizing Microsoft.Xna.Framework;

namespace PuzzleGame
    /// Keyframe animation helper class.
    public class Animation
        /// Listing of keyframes within the animation.
        Listing<Keyframe> keyframes = new Listing<Keyframe>();

        /// Present place within the animation.
        int timeline;

        /// The final body of the animation (set when keyframes are added).
        int lastFrame = 0;

        /// Marks the animation as able to run/working.
        bool run = false;

        /// Present keyframe index.
        int currentIndex;

        /// Assemble new animation helper.
        public Animation()

        /// Add a keyframe to the animation.
        /// Time for keyframe to occur.
        /// Worth at keyframe.
        public void AddKeyframe(int time, float worth)
            Keyframe ok = new Keyframe();
            ok.time = time;
            ok.worth = worth;
            keyframes.Kind(delegate(Keyframe a, Keyframe b) { return a.time.CompareTo(b.time); });
            lastFrame = (time > lastFrame) ? time : lastFrame;

        /// Reset the animation and flag it as able to run.
        public void Begin()
            timeline = 0;
            currentIndex = 0;
            run = true;

        /// Replace the animation timeline.
        /// Present recreation time.
        /// Reference to worth to alter.
        public void Replace(GameTime gameTime, ref float worth)
            if (run)
                timeline += gameTime.ElapsedGameTime.Milliseconds;
                worth = MathHelper.SmoothStep(keyframes[currentIndex].worth, keyframes[currentIndex + 1].worth
                (float)timeline / (float)keyframes[currentIndex + 1].time);
                if (timeline >= keyframes[currentIndex + 1].time && currentIndex != keyframes.Depend) { currentIndex++; }
                if (timeline >= lastFrame) { run = false; }

        /// Represents a keyframe on the timeline.
        public struct Keyframe
            public int time;
            public float worth;

useful resource:




Skeletal Animation[edit]

Skeletal animation is the method in pc animation which is represented in two components, the pores and skin half (known as mesh) and the skeleton half (known as rig). The pores and skin is represented as a mixture of surfaces and the skeleton is a mixture of bones. These bones are linked to one another like actual bones and a part of a hierarchical set. The result’s, you progress one bone and the bones which ought to work together transfer too. The bones animate the mesh (the surfaces) in the identical approach. Whereas this system is usually used to animate people or extra typically for natural modeling, it solely serves to make the animation course of extra intuitive and the identical method can be utilized to manage the deformation of any object, a constructing, a automobile, and so forth.

This method is kind of helpful for the animators as a result of in all animation techniques is this easy method a port of. So they do not want any complicated algorithms to animate the fashions. With out this system it’s just about unattainable to animate the mesh together with the bones.


Rigging is the method to create a skeleton to animate a mannequin. This skeleton consists of bones(rigs) and joins that are the connetion between the bones. Commonly you associates this bones and joins with the property of an actual skeleton. For instance you create first the higher leg as a bone and afterwards you construct the knee as a be part of.


Skinning is the method to create a pores and skin which is assigned to a wired body (the bones) and the motion of the pores and skin is just like the motion of the bones.The skinning comes intuitive after the rigging. The variations between skinning and rigging is,skinning is the visible deformation of the physique(your mannequin).
Helpful is the truth that it’s potential to setup each single sufaces, that is very useful in conditions just like the movement of an arm. Even you progress your arm (or the arm of the mannequin), your pores and skin (the surfaces of the mannequin) work together with the movement in another way, decided by the place like on the inside your elbow or on the outdoors of your elbow.
It is usually potential to simulate muscular motion on this context.

The bones and polygons of your mannequin have a restrict in XNA:[edit]

  1. Bones: 59 as much as 79 in 4.0
  2. Polygons: relies on the {hardware}
Typical applications are:[edit]

Animations in XNA[edit]

The only method to get animations out of your mannequin in XNA is to create animations in your 3d improvement device. These animations are robotically part of your exported .x flile or .fbx file.

A easy method to present the dealing with with animations in XNA is a pleasant demo from

First we want a mannequin and a animation:

Mannequin currentModel;
        AnimationPlayer animationPlayer;

The subsequent step is to replace the LoadContent() technique:

protected override void LoadContent()
            // Load the mannequin.
            currentModel = Content material.Load<Mannequin>("dude");

            // Search for our customized skinning info.
            SkinningData skinningData = currentModel.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This mannequin doesn't include a SkinningData tag.");

            // Create an animation participant, and begin decoding an animation clip.
            animationPlayer = new AnimationPlayer(skinningData);

            AnimationClip clip = skinningData.AnimationClips["Take 001"];


If you happen to setup your clib variable as an array it can save you a variety of totally different animations:

AnimationClip clips= new AnimationClip[skinningData.AnimationClips.Keys.Count];
clips[0] = skinningData.AnimationClips["moveleft"];
clips[1] = skinningData.AnimationClips["moveright"];
clips[2] = skinningData.AnimationClips["jump"];

After that’s is straightforward to name the totally different animations, for instance by dragging the leap key.


The identical applies to all of the others animations.





What we learnt on this chapter[edit]

On this chapter we discovered, find out how to animate our character in two other ways. First the keyframe-animation and than the skeleton-animation. These two strategies are an important in xna.

However which one is best?[edit]

Higher on this context is the improper phrase, lets substitute the phrase “higher” with the phrases “higher through which state of affairs”.
Its easy… use the skeleton-animation in 3D and the keyframe-animation within the 2D space.




A.Rei and FixSpix

Related posts

Leave a Comment