public void Update(float elapsedSeconds, ref SpriteState jointState) { if (JointAnim.FrameCount > 1) { timeSinceFrameChange += elapsedSeconds; while (timeSinceFrameChange > currentSectionLength) { timeSinceFrameChange -= currentSectionLength; currentKeyframeIndex = nextKeyframeIndex; nextKeyframeIndex = (nextKeyframeIndex + 1) % JointAnim.FrameCount; int fn1 = JointAnim.GetFrameNumber(currentKeyframeIndex); int fn2 = JointAnim.GetFrameNumber(nextKeyframeIndex); int frameDifference = fn2 > fn1 ? fn2 - fn1 : (JointAnim.ParentClipAnim.Duration - fn1) + fn2; currentSectionLength = frameDifference / JointAnim.ParentClipAnim.Framerate; } } float lerpValue = currentSectionLength == 0 ? 0 : timeSinceFrameChange / currentSectionLength; JointAnim.ApplySate(currentKeyframeIndex, nextKeyframeIndex, lerpValue, ref jointState); //Transform2D key1 = JointAnim.Frames[currentKeyframeIndex].Transform; //Transform2D key2 = JointAnim.Frames[nextKeyframeIndex].Transform; //Transform2D.Lerp(ref key1, ref key2, timeSinceFrameChange / currentSectionLength, ref CurrentKeyframe); }
public override void ApplySate(int currentKeyframeIndex, int nextKeyframeIndex, float lerpValue, ref SpriteState jointState) { Frame f = Frames[currentKeyframeIndex]; jointState.TextureRect = f.TexRect; jointState.Texture = f.Texture; jointState.FlipState = f.FlipState; jointState.Visible = f.Visible; }
public override void ApplySate(int currentKeyframeIndex, int nextKeyframeIndex, float lerpValue, ref SpriteState jointState) { TweenType tweenType = Frames[currentKeyframeIndex].Tween; if (tweenType == TweenType.none) { jointState.Transform = Frames[currentKeyframeIndex].Transform; } else { int tweenEase = Frames[currentKeyframeIndex].EaseValue; //if (tweenType == TweenType.motion) //{ if (tweenEase > 0) { lerpValue = Easing.QuadraticEaseOut(lerpValue, (float)tweenEase / 100.0f); } else if (tweenEase < 0) { lerpValue = Easing.QuadraticEaseIn(lerpValue, (float)tweenEase / -100.0f); } //} //else //{ // if (tweenType == TweenType.motionCustomAll) // { // Vector2[] bezier = Frames[currentKeyframeIndex].CustomEaseAll; // // determine segment id // int segId = 3; // while (segId < bezier.Length && lerpValue > bezier[segId].X) // { // segId += 3; // } // float endTime = bezier[segId].X; // float startTime = bezier[segId - 3].X; // float lerpInternal = (lerpValue - startTime) / (endTime - startTime); // Easing.CubicBezierCurve( // } //} Transform2D.Lerp( ref Frames[currentKeyframeIndex].Transform, ref Frames[nextKeyframeIndex].Transform, lerpValue, ref jointState.Transform); } }
public void Draw(SpriteBatch spriteBatch) { for (int i = 0; i < Clip.DrawOrder.Length; ++i) { int index = Clip.DrawOrder[i]; SpriteState js = JointStates[index]; if (js.Texture != null && js.Visible) { Transform2D xform = AbsoluteTransforms[index]; spriteBatch.Draw( js.Texture, new Vector2((int)xform.Pos.X, (int)xform.Pos.Y), new Rectangle?(js.TextureRect), js.Color, xform.Rot, xform.Origin, xform.Scale, js.FlipState, 0.0f); } } }
public override void ApplySate(int currentKeyframeIndex, int nextKeyframeIndex, float lerpValue, ref SpriteState jointState) { if (Frames[currentKeyframeIndex].Tween == TweenType.none) { jointState.Color = Frames[currentKeyframeIndex].Color; } else { int tweenEase = Frames[currentKeyframeIndex].EaseValue; if (tweenEase > 0) { lerpValue = Easing.QuadraticEaseOut(lerpValue, (float)tweenEase / 100.0f); } else if (tweenEase < 0) { lerpValue = Easing.QuadraticEaseIn(lerpValue, (float)tweenEase / -100.0f); } jointState.Color = Color.Lerp( Frames[currentKeyframeIndex].Color, Frames[nextKeyframeIndex].Color, lerpValue); } }
public virtual void ApplySate(int currentKeyframeIndex, int nextKeyframeIndex, float lerpValue, ref SpriteState jointState) { }