public void SetCurrentAnimation(string name) { if (!_animations.ContainsKey(name)) { throw new ArgumentException("cannot find the animation: " + name); } if (name != _currentAnimation) { if (!CurrentAnimation.FinishBeforeTransition) { // Switch immediately to the new animation _currentAnimation = name; CurrentAnimation.Reset(); } else { // Set the current animation to wait for the end, upon finishing, switch animations CurrentAnimation.WaitForEnd(); EventHandler <AnimationEventArgs> animSwitch = (sender, args) => { _currentAnimation = name; CurrentAnimation.Reset(); }; CurrentAnimation.AnimationFinished += animSwitch; } } }