/// <summary>
        /// Gets the mix.
        /// </summary>
        /// <param name="from">Animation From.</param>
        /// <param name="to">Animation To.</param>
        /// <returns>return mix result.</returns>
        public float GetMix(Animation from, Animation to)
        {
            KeyValuePair<Animation, Animation> key = new KeyValuePair<Animation, Animation>(from, to);
            float duration;
            this.animationToMixTime.TryGetValue(key, out duration);

            return duration;
        }
Beispiel #2
0
        /// <summary>
        /// Adds the animation.
        /// </summary>
        /// <param name="animation">The animation.</param>
        /// <exception cref="System.ArgumentNullException">animation cannot be null.</exception>
        public void AddAnimation(Animation animation)
        {
            if (animation == null)
            {
                throw new ArgumentNullException("animation cannot be null.");
            }

            this.Animations.Add(animation);
        }
Beispiel #3
0
        /// <summary>
        /// Sets the animation internal.
        /// </summary>
        /// <param name="animation">The animation.</param>
        /// <param name="loop">if set to <c>true</c> [loop].</param>
        private void SetAnimationInternal(Animation animation, bool loop)
        {
            this.previous = null;
            if (animation != null && Animation != null)
            {
                this.mixDuration = this.Data.GetMix(Animation, animation);

                if (this.mixDuration > 0)
                {
                    this.mixTime = 0;
                    this.previous = this.Animation;
                    this.previousTime = this.Time;
                    this.previousLoop = this.Loop;
                }
            }

            this.Animation = animation;
            this.Loop = loop;
            this.Time = 0;
        }
        /// <summary>
        /// Sets the mix.
        /// </summary>
        /// <param name="from">Animation from.</param>
        /// <param name="to">Animation To.</param>
        /// <param name="duration">The duration.</param>
        /// <exception cref="System.ArgumentNullException">from cannot be null.</exception>
        public void SetMix(Animation from, Animation to, float duration)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from cannot be null.");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to cannot be null.");
            }

            KeyValuePair<Animation, Animation> key = new KeyValuePair<Animation, Animation>(from, to);
            this.animationToMixTime.Remove(key);

            if (duration > 0)
            {
                this.animationToMixTime.Add(key, duration);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Sets the animation.
        /// </summary>
        /// <param name="animation">The animation.</param>
        /// <param name="loop">if set to <c>true</c> [loop].</param>
        /// <param name="mixDuration">Mix duration</param>
        /// /// <param name="skeleton">Animation skeleton</param>
        public void SetAnimation(Animation animation, bool loop, float mixDuration, Skeleton skeleton)
        {
            if (this.Animation != null)
            {
                if (this.previous != null)
                {
                    this.Animation.Mix(skeleton, this.Time, this.Loop, 1);
                    this.Data.SetMix(this.previous, this.Animation, 0);
                }

                this.Data.SetMix(this.Animation, animation, mixDuration);
            }

            this.queue.Clear();
            this.SetAnimationInternal(animation, loop);
        }
Beispiel #6
0
 /// <summary>
 /// Clears the animation.
 /// </summary>
 public void ClearAnimation()
 {
     this.previous = null;
     Animation = null;
     this.queue.Clear();
 }
Beispiel #7
0
        /// <summary>
        /// Applies the specified skeleton.
        /// </summary>
        /// <param name="skeleton">The skeleton.</param>
        public void Apply(Skeleton skeleton)
        {
            if (Animation == null)
            {
                return;
            }

            if (this.previous != null)
            {
                this.previous.Apply(skeleton, this.previousTime, this.previousLoop);
                float alpha = this.mixTime / this.mixDuration;
                if (alpha >= 1)
                {
                    alpha = 1;
                    this.previous = null;
                }

                Animation.Mix(skeleton, this.Time, this.Loop, alpha);
            }
            else
            {
                Animation.Apply(skeleton, this.Time, this.Loop);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Adds an animation to be played delay seconds after the current or last queued animation.
        /// </summary>
        /// <param name="animation">The animation.</param>
        /// <param name="loop">if set to <c>true</c> [loop].</param>
        /// <param name="delay">May be minor equal than 0 to use duration of previous animation minus any mix duration plus the negative delay.</param>
        public void AddAnimation(Animation animation, bool loop, float delay)
        {
            QueueEntry entry = new QueueEntry();
            entry.Animation = animation;
            entry.Loop = loop;

            if (delay <= 0)
            {
                Animation previousAnimation = this.queue.Count == 0 ? this.Animation : this.queue[this.queue.Count - 1].Animation;
                if (previousAnimation != null)
                {
                    delay = previousAnimation.Duration - this.Data.GetMix(previousAnimation, animation) + delay;
                }
                else
                {
                    delay = 0;
                }
            }

            entry.Delay = delay;
            this.queue.Add(entry);
        }
Beispiel #9
0
 /// <summary>
 /// Adds the animation.
 /// </summary>
 /// <param name="animation">The animation.</param>
 /// <param name="loop">if set to <c>true</c> [loop].</param>
 public void AddAnimation(Animation animation, bool loop)
 {
     this.AddAnimation(animation, loop, 0);
 }