private void updateAnimations(float deltaTime) { float baseAnimSpeed = 1; float topAnimSpeed = 1; mTimer += deltaTime; if (mTopAnimID == AnimID.ANIM_DRAW_SWORDS) { // flip the draw swords animation if we need to put it back topAnimSpeed = mSwordsDrawn ? -1 : 1; // half-way through the animation is when the hand grasps the handles... if (mTimer >= mAnims[(int)mTopAnimID].Length / 2 && mTimer - deltaTime < mAnims[(int)mTopAnimID].Length / 2) { // so transfer the swords from the sheaths to the hands mBodyEnt.DetachAllObjectsFromBone(); mBodyEnt.AttachObjectToBone(mSwordsDrawn ? "Sheath.L" : "Handle.L", mSword1); mBodyEnt.AttachObjectToBone(mSwordsDrawn ? "Sheath.R" : "Handle.R", mSword2); // change the hand state to grab or let go mAnims[(int)AnimID.ANIM_HANDS_CLOSED].Enabled = !mSwordsDrawn; mAnims[(int)AnimID.ANIM_HANDS_RELAXED].Enabled = mSwordsDrawn; // toggle sword trails if (mSwordsDrawn) { mSwordTrail.Visible = false; mSwordTrail.RemoveNode(mSword1.ParentNode); mSwordTrail.RemoveNode(mSword2.ParentNode); } else { mSwordTrail.Visible = true; mSwordTrail.AddNode(mSword1.ParentNode); mSwordTrail.AddNode(mSword2.ParentNode); } } if (mTimer >= mAnims[(int)mTopAnimID].Length) { // animation is finished, so return to what we were doing before if (mBaseAnimID == AnimID.ANIM_IDLE_BASE) { setTopAnimation(AnimID.ANIM_IDLE_TOP); } else { setTopAnimation(AnimID.ANIM_RUN_TOP); mAnims[(int)AnimID.ANIM_RUN_TOP].TimePosition = mAnims[(int)AnimID.ANIM_RUN_BASE].TimePosition; } mSwordsDrawn = !mSwordsDrawn; } } else if (mTopAnimID == AnimID.ANIM_SLICE_VERTICAL || mTopAnimID == AnimID.ANIM_SLICE_HORIZONTAL) { if (mTimer >= mAnims[(int)mTopAnimID].Length) { // animation is finished, so return to what we were doing before if (mBaseAnimID == AnimID.ANIM_IDLE_BASE) { setTopAnimation(AnimID.ANIM_IDLE_TOP); } else { setTopAnimation(AnimID.ANIM_RUN_TOP); mAnims[(int)AnimID.ANIM_RUN_TOP].TimePosition = mAnims[(int)AnimID.ANIM_RUN_BASE].TimePosition; } } // don't sway hips from side to side when slicing. that's just embarrasing. if (mBaseAnimID == AnimID.ANIM_IDLE_BASE) { baseAnimSpeed = 0; } } else if (mBaseAnimID == AnimID.ANIM_JUMP_START) { if (mTimer >= mAnims[(int)mBaseAnimID].Length) { // takeoff animation finished, so time to leave the ground! setBaseAnimation(AnimID.ANIM_JUMP_LOOP, true); // apply a jump acceleration to the character mVerticalVelocity = JUMP_ACCEL; } } else if (mBaseAnimID == AnimID.ANIM_JUMP_END) { if (mTimer >= mAnims[(int)mBaseAnimID].Length) { // safely landed, so go back to running or idling if (mKeyDirection == Mogre.Vector3.ZERO) { setBaseAnimation(AnimID.ANIM_IDLE_BASE); setTopAnimation(AnimID.ANIM_IDLE_TOP); } else { setBaseAnimation(AnimID.ANIM_RUN_BASE, true); setTopAnimation(AnimID.ANIM_RUN_TOP, true); } } } // increment the current base and top animation times if (mBaseAnimID != AnimID.ANIM_NONE) { mAnims[(int)mBaseAnimID].AddTime(deltaTime * baseAnimSpeed); } if (mTopAnimID != AnimID.ANIM_NONE) { mAnims[(int)mTopAnimID].AddTime(deltaTime * topAnimSpeed); } // apply smooth transitioning between our animations fadeAnimations(deltaTime); }
/// <summary> /// /// </summary> /// <param name="deltaTime"></param> private void UpdateAnimations(Real deltaTime) { Real baseAnimSpeed = 1; Real topAnimSpeed = 1; timer += deltaTime; if (topAnimID == AnimationID.DrawSword) { // flip the draw swords animation if we need to put it back topAnimSpeed = swordsDrawn ? -1 : 1; // half-way through the animation is when the hand grasps the handles... if (timer >= anims[(int)topAnimID].Length / 2 && timer - deltaTime < anims[(int)topAnimID].Length / 2) { // toggle sword trails swordTrail.IsVisible = !swordsDrawn; // so transfer the swords from the sheaths to the hands if (swordsDrawn) { swordTrail.RemoveNode(sword1.ParentNode); swordTrail.RemoveNode(sword2.ParentNode); } bodyEnt.DetachAllObjectsFromBone(); bodyEnt.AttachObjectToBone(swordsDrawn ? "Sheath.L" : "Handle.L", sword1); bodyEnt.AttachObjectToBone(swordsDrawn ? "Sheath.R" : "Handle.R", sword2); if (!swordsDrawn) { swordTrail.AddNode(sword1.ParentNode); swordTrail.AddNode(sword2.ParentNode); } // change the hand state to grab or let go anims[(int)AnimationID.HandsClosed].IsEnabled = !swordsDrawn; anims[(int)AnimationID.HandsRelaxed].IsEnabled = swordsDrawn; } //end if if (timer >= anims[(int)topAnimID].Length) { // animation is finished, so return to what we were doing before if (baseAnimID == AnimationID.IdleBase) { SetTopAnimation(AnimationID.IdleTop); } else { SetTopAnimation(AnimationID.RunTop); anims[(int)AnimationID.RunTop].Time = anims[(int)AnimationID.RunBase].Time; } swordsDrawn = !swordsDrawn; } //end if } //end if else if (topAnimID == AnimationID.SliceVertical || topAnimID == AnimationID.SliceHorizontal) { if (timer >= anims[(int)topAnimID].Length) { // animation is finished, so return to what we were doing before if (baseAnimID == AnimationID.IdleBase) { SetTopAnimation(AnimationID.IdleTop); } else { SetTopAnimation(AnimationID.RunTop); anims[(int)AnimationID.RunTop].Time = anims[(int)AnimationID.RunBase].Time; } } // don't sway hips from side to side when slicing. that's just embarrasing. if (baseAnimID == AnimationID.IdleBase) { baseAnimSpeed = 0; } } //end else if else if (baseAnimID == AnimationID.JumpStart) { if (timer >= anims[(int)baseAnimID].Length) { // takeoff animation finished, so time to leave the ground! SetBaseAnimation(AnimationID.JumpLoop, true); // apply a jump acceleration to the character verticalVelocity = JumpAcceleration; } } //end if else if (baseAnimID == AnimationID.JumpEnd) { if (timer >= anims[(int)baseAnimID].Length) { // safely landed, so go back to running or idling if (keyDirection == Axiom.Math.Vector3.Zero) { SetBaseAnimation(AnimationID.IdleBase); SetTopAnimation(AnimationID.IdleTop); } else { SetBaseAnimation(AnimationID.RunBase, true); SetTopAnimation(AnimationID.RunTop, true); } } } // increment the current base and top animation times if (baseAnimID != AnimationID.None) { anims[(int)baseAnimID].AddTime(deltaTime * baseAnimSpeed); } if (topAnimID != AnimationID.None) { anims[(int)topAnimID].AddTime(deltaTime * topAnimSpeed); } // apply smooth transitioning between our animations FadeAnimations(deltaTime); }