コード例 #1
0
        /// <summary>
        /// Sets the frame for the current active animation.
        /// </summary>
        /// <param name="frame">
        /// The frame index.
        /// </param>
        public void SetFrame(int frame)
        {
            StripAnimation stripAnimation = this.animations[this.currentAnimation];

            stripAnimation.CurrentFrameIndex = frame;
            this.CurrentRectangle            = this.animations[this.currentAnimation].CurrentFrame;
        }
コード例 #2
0
        /// <summary>
        /// Adds an animation to this behavior.
        /// </summary>
        /// <param name="animationName">
        /// Name of the animation to add.
        /// </param>
        /// <param name="animation">
        /// The animation to add.
        /// </param>
        /// <remarks>
        /// If there is already an animation with the same animation name, it will be overwritten.
        /// </remarks>
        /// <returns>
        /// The <see cref="Animation2D"/> it-self.
        /// </returns>
        public Animation2D Add(string animationName, StripAnimation animation)
        {
            this.animations.Add(animationName, animation);

            if (this.currentAnimation == null)
            {
                this.CurrentAnimation = this.AnimationNames.First();
                this.CurrentRectangle = this.animations[this.currentAnimation].CurrentFrame;
            }

            return(this);
        }
コード例 #3
0
        /// <summary>
        /// Updates the animation.
        /// </summary>
        /// <param name="gameTime">
        /// The game time.
        /// </param>
        protected override void Update(TimeSpan gameTime)
        {
            if (this.state == AnimationState.Playing && !string.IsNullOrEmpty(this.currentAnimation))
            {
                StripAnimation stripAnimation = this.animations[this.currentAnimation];
                if (this.targetFrame.HasValue && (this.targetFrame.Value == stripAnimation.CurrentFrameIndex))
                {
                    this.Stop();
                    this.targetFrame = null;
                    return;
                }

                if (!this.loop && stripAnimation.CurrentFrameIndex + 1 >= stripAnimation.NumFrames)
                {
                    this.Stop();
                    return;
                }

                stripAnimation.Update(gameTime);
                this.CurrentRectangle = stripAnimation.CurrentFrame;
            }
        }