public void Update(float elapsedSeconds, float totalSeconds) { if (CurrentAnimation.IsScaledWithEntity) { float speed = Entity.Body.LinearVelocity.Length(); float factor = CurrentAnimation.EntitySpeedOffset + speed * CurrentAnimation.EntitySpeedScale; totalSecondsSinceLastSwitch += elapsedSeconds * factor; } else { totalSecondsSinceLastSwitch += elapsedSeconds; } float currentDuration = CurrentAnimation.Duration; int inAnimationNum = (int)((totalSecondsSinceLastSwitch % currentDuration) / currentDuration * CurrentAnimation.FrameNumbers.Length); inAnimationNum = Math.Min(CurrentAnimation.FrameNumbers.Length - 1, Math.Max(0, inAnimationNum)); int inImageFrameNum = CurrentAnimation.FrameNumbers[inAnimationNum]; SetSourceRectangle(inImageFrameNum); if (NextAnimation != null && neutralFrames.Contains(inImageFrameNum)) { CurrentAnimation = NextAnimation; NextAnimation = null; totalSecondsSinceLastSwitch = 0f; } }
public void SwitchTo(string animationName) { if (animationName != CurrentAnimation.Name) { NextAnimation = animByName[animationName]; } }