示例#1
0
        private TextureFrame GetFrameForwardBackwardOnce(TimeSpan time)
        {
            TimeSpan startDelay = TimeSpan.Zero;

            for (int i = 0; i < this.frames.Count; i++)
            {
                TextureFrame frame = this.frames[i];
                if (CheckFrameDelay(startDelay, frame, time))
                {
                    return(frame);
                }

                startDelay += frame.Duration;
            }

            for (int i = this.frames.Count - 1; i >= 0; i--)
            {
                TextureFrame frame = this.frames[i];
                if (CheckFrameDelay(startDelay, frame, time))
                {
                    return(frame);
                }

                startDelay += frame.Duration;
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Gets a frame according to the specified animation time.
        /// </summary>
        /// <param name="time">The animation time.</param>
        /// <returns>The frame that corresponds to the specified animation time.</returns>
        public TextureFrame GetFrameFromTime(TimeSpan time)
        {
            if (this.frames.Count == 1)
            {
                return(this.frames[0]);
            }

            TextureFrame retValue = null;

            switch (this.FrameAnimationMode)
            {
            case FrameAnimationMode.ForwardOnce:
                retValue = this.GetFrameForwardOnce(time) ?? this.frames[this.frames.Count - 1];
                break;

            case FrameAnimationMode.BackwardOnce:
                retValue = this.GetFrameBackwardOnce(time) ?? this.frames[0];
                break;

            case FrameAnimationMode.ForwardLoop:
                retValue = this.GetFrameForwardLoop(time);
                break;

            case FrameAnimationMode.BackwardLoop:
                retValue = this.GetFrameBackwardLoop(time);
                break;

            case FrameAnimationMode.ForwardBackwardOnce:
                retValue = this.GetFrameForwardBackwardOnce(time) ?? this.frames[0];
                break;

            case FrameAnimationMode.ForwardBackwardLoop:
                retValue = this.GetFrameForwardBackwardLoop(time);
                break;
            }

            return(retValue);
        }
示例#3
0
 private static bool CheckFrameDelay(TimeSpan startDelay, TextureFrame frame, TimeSpan time)
 {
     return(startDelay <= time && startDelay + frame.Duration >= time);
 }