/// <summary> /// Create an animation. /// </summary> /// <param name="skeleton">The skeleton this animation belongs to.</param> public Animation(Skeleton skeleton) { //Initialize stuff. Initialize(skeleton); }
/// <summary> /// Initialize the animation. /// <param name="skeleton">The skeleton this animation belongs to.</param> /// </summary> public void Initialize(Skeleton skeleton) { //Initialize a few variables. _Skeleton = skeleton; _Keyframes = new List<Keyframe>(); _FrameTime = .2f; _NumberOfFrames = 20; _CurrentFrameIndex = 0; _NextFrameIndex = 0; _IsActive = false; _TotalElapsedTime = 0; _Strength = 1; //Create the first keyframe and reset it to the state of the skeleton. AddKeyframe(); ResetKeyframe(0); }
/// <summary> /// Intialize the bone. /// </summary> /// <param name="skeleton">The skeleton this bone is a part of.</param> /// <param name="name">The name of the bone.</param> /// <param name="index">The index of the bone.</param> /// <param name="parentIndex">The index of the parent bone.</param> /// <param name="position">The absolute position of the bone.</param> /// <param name="scale">The scale of the bone.</param> /// <param name="rotation">The absolute rotation of the bone.</param> /// <param name="length">The length of the bone.</param> private void Initialize(Skeleton skeleton, string name, int index, int parentIndex, Vector2 position, Vector2 scale, float rotation, float length) { //Save the given index for future use, along with initializing a few things. _Skeleton = skeleton; _Name = name; _Index = index; _ParentIndex = parentIndex; _RootBone = false; _Scale = scale; _AbsolutePosition = position; _AbsoluteRotation = rotation; _RelativePosition = Vector2.Zero; _RelativeRotation = rotation; _Length = length; _RelativeDirection = 0; //Check if the bone is the skeleton's root bone. if (parentIndex == -1) { _RootBone = true; } else { //Calculate the position relative to the bone's parent. UpdateRelativePosition(); UpdateRelativeRotation(); UpdateRelativeDirection(); } }
/// <summary> /// Create a bone. /// </summary> /// <param name="skeleton">The skeleton this bone is a part of.</param> /// <param name="name">The name of the bone.</param> /// <param name="index">The index of the bone.</param> /// <param name="parentIndex">The index of the parent bone.</param> /// <param name="position">The absolute position of the bone.</param> /// <param name="scale">The scale of the bone.</param> /// <param name="rotation">The absolute rotation of the bone.</param> /// <param name="length">The length of the bone.</param> public Bone(Skeleton skeleton, string name, int index, int parentIndex, Vector2 position, Vector2 scale, float rotation, float length) { Initialize(skeleton, name, index, parentIndex, position, scale, rotation, length); }
/// <summary> /// Set this keyframe to the state of a skeleton. /// </summary> /// <param name="skeleton">The skeleton to mimick.</param> public void SetBones(Skeleton skeleton) { //Clear the list of bones. _BonesToBe.Clear(); //Add all bones in the skeleton to the keyframe. foreach (Bone bone in skeleton.Bones) { AddBone(bone.DeepClone()); } }