コード例 #1
0
 // Constructor for an Animation Player. Sets up the initial paramters such as
 // this player's animation, current frame, and time displayed.
 // param: game - The over-arching Game object.
 // param: spriteBatch - The spriteBatch used to draw the Animation.
 // param: animation - The Animation to play.
 /// <summary>
 /// Constructor for an Animation Player. Sets up the initial parameters, including
 /// the player's animation, current frame, and time displayed.
 /// </summary>
 /// <param name="spriteBatch">The sprite batch used to draw this animation.</param>
 /// <param name="animation">The desired animation to begin playing.</param>
 public AnimationPlayer(SpriteBatch spriteBatch, Animation animation)
 {
     this.animation = animation;
     this.timeDisplayed = 0;
     this.currentFrame = animation.Frames[DEFAULT_START_FRAME];
     playStart = DEFAULT_START_FRAME;
     playStop = animation.FrameCount - 1;
 }
コード例 #2
0
        // Changes the Animation's frame to the next frame in the sequence.
        private void IncrementFrame()
        {
            List<Frame> currentAnimation = animation.Frames;

            if (Animation.IsLooping)
            {
                currentFrame = currentAnimation[(currentFrame.FrameIndex + 1) % (playStop+1)];
                ResetTime();
            }
            else
            {
                currentFrame = currentAnimation[Math.Min(currentFrame.FrameIndex + 1, playStop)];

                if (currentFrame.FrameIndex != playStop)
                {
                    ResetTime();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Begins or continues playback of an animation from the desired
        /// start and end frames.
        /// </summary>
        /// <param name="animation">The animation to play.</param>
        /// <param name="start">The frame index to start animating from.</param>
        /// <param name="end">The frame index to end animating on.</param>
        public void PlayAnimation(Animation newAnimation, int start, int end)
        {
            // If this animation is already running, do not restart it.
            if (Animation == newAnimation)
                return;

            if ((start >= 0) && (start <= newAnimation.FrameCount - 1) &&
                (end >= 0) && (end <= newAnimation.FrameCount - 1))
            {
                playStart = start;
                playStop = end;
            }
            else
            {
                playStart = DEFAULT_START_FRAME;
                playStop = newAnimation.FrameCount - 1;
            }

            //Reset the hasDraw values to false for each of this animation's
            //frames.
            ResetDraw();

            // Start the new animation.
            this.animation = newAnimation;
            currentFrame = this.animation.Frames[playStart];
            ResetTime();
        }
コード例 #4
0
 // Sets the next animation draw cycle to a specific frame in the current sequence
 // param: frameIndex - the index of the Frame to be drawn
 public void SetFrame(int frameIndex)
 {
     currentFrame = Animation.Frames[frameIndex];
 }
コード例 #5
0
        /// <summary>
        /// Begins or continues playback of an animation from the beginning to
        /// the end of an animation.
        /// </summary>
        /// <param name="animation">The animation to play.</param>
        public void PlayAnimation(Animation newAnimation)
        {
            // If this animation is already running, do not restart it.
            if (Animation == newAnimation)
                return;

            //Reset the hasDraw values to false for each of this animation's
            //frames.
            ResetDraw();

            // Start the new animation.
            this.animation = newAnimation;
            currentFrame = this.animation.Frames[0];
            playStart = DEFAULT_START_FRAME;
            playStop = this.animation.FrameCount - 1;
            ResetTime();
        }