Example #1
0
        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;
                }
            }
        }
Example #2
0
 public override void Reset()
 {
     if (!IsGhost)
     {
         CurrentAnimation = ConstructionAnimation;
         CurrentAnimation.Reset();
     }
 }
Example #3
0
 internal void SetAnimation(SPRITE_ANIMATION newAnimationState)
 {
     if (newAnimationState != CurrentAnimationState)
     {
         CurrentAnimationState = newAnimationState;
         CurrentAnimation.Reset();
     }
 }
Example #4
0
        public void ResetAnimation()
        {
            if (CurrentAnimation == null)
            {
                return;
            }

            CurrentAnimation.Reset();
        }
Example #5
0
        /// <summary>
        /// Set the current animation to a specific frame.
        /// </summary>
        /// <param name="frame">The frame in terms of the animation.</param>
        public void SetFrame(int frame)
        {
            if (!Active)
            {
                return;
            }

            CurrentAnimation.CurrentFrameIndex = frame;
            CurrentAnimation.Reset();
        }
Example #6
0
        /// <summary>
        /// Plays an animation.  If no animation is specified, play the buffered animation.
        /// </summary>
        public void Play()
        {
            Active = true;

            if (BufferedAnimation != null)
            {
                Play(BufferedAnimation.Name);
            }
            else
            {
                CurrentAnimation.Reset();
            }
        }
Example #7
0
        public Animation Play(string key)
        {
            Animation anim;

            if (Animations.TryGetValue(key, out anim))
            {
                //Console.WriteLine("playing anim " + key);

                CurrentAnimation = anim;
                CurrentAnimation.Reset();

                return(anim);
            }

            return(null);
        }
Example #8
0
        public void Play(string a)
        {
            if (!Animations.ContainsKey(a))
            {
                Debugger.Instance.Log("Cannot play animation " + a + " on " + Name);
                return;
            }
            Active = true;
            var pastAnim = CurrentAnimation.Name;

            CurrentAnimationName = a;
            if (CurrentAnimation != Animations[pastAnim])
            {
                CurrentAnimation.Reset();
            }
        }
Example #9
0
        internal virtual void SetCurrentAnimationByName(string name, double?overrideDelay = null)
        {
            if (CurrentAnimation != null)
            {
                //CurrentAnimation.OnAnimationDidStart = null;
                //CurrentAnimation.OnAnimationDidFinish = null;
            }

            SpriteAnimation animation = (from anim in allAnimations where anim.Name.ToLowerInvariant() == name.ToLowerInvariant() select anim).FirstOrDefault();

            if (animation != null)
            {
                CurrentAnimation = animation;
                if (overrideDelay != null)
                {
                    CurrentAnimation.FrameDelay = overrideDelay.Value;
                }
                CurrentAnimation.Reset();
            }
        }
Example #10
0
        public Animation Play(string key)
        {
            Animation anim;

            if (Animations.TryGetValue(key, out anim))
            {
                // check if the current animation that is playing
                // is not already the one we want to play
                if (CurrentAnimation?.Name == key && CurrentAnimation.IsPlaying)
                {
                    return(CurrentAnimation);
                }

                CurrentAnimation = anim;
                CurrentAnimation.Reset();

                return(anim);
            }

            return(null);
        }
Example #11
0
        public void SetAnimationFrameRate(float frameRate, bool allFrames)
        {
            if (CurrentAnimation == null)
            {
                return;
            }

            if (allFrames)
            {
                CurrentAnimation.FrameRate = frameRate;
            }
            else
            {
                foreach (var frame in SelectedFrames)
                {
                    CurrentAnimation.SetFrameDuration(frame.Num, 1f / frameRate);
                }
            }


            CurrentAnimation.Reset();
        }
Example #12
0
 /// <summary>
 /// Resets the current animation back to the first frame.
 /// </summary>
 public void Reset()
 {
     CurrentAnimation.Reset();
 }