internal InactiveState(AnimationInstance animation) { //this.animation = animation; Update = (GameTime time) => { if (animation.IsPlaying) { return(new ActiveState(animation)?.Update(time)); } return(this); }; Draw = null; }
internal PausedState(AnimationInstance animation) { //this.animation = animation; Update = (GameTime time) => { if (animation.IsPlaying) { return(new ActiveState(animation)?.Update(time)); } return(this); }; Draw = (SpriteBatch batch) => { if (animation.Posit == null) { if (animation.Animation.UseEachFramesDrawEffects) { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch); } else { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch, animation.Animation.DrawEffects); } } else { if (animation.Animation.UseEachFramesDrawEffects) { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch, null, animation.Posit.Value); } else { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch, animation.Animation.DrawEffects, animation.Posit.Value); } } }; }
internal CompletedState(AnimationInstance animation) { //this.animation = animation; Update = (GameTime time) => { return(this); }; Draw = null; }
internal ActiveState(AnimationInstance animation) { //this.animation = animation; Update = (GameTime gameTime) => { IAnimationState toReturn = this; if (animation.IsPlaying) { // Add to the time counter. - J Mor animation.timeSinceLastFrameChange += (float)gameTime.ElapsedGameTime.TotalSeconds; // If enough time has gone by to actually change frames... while (animation.timeSinceLastFrameChange >= animation.SecondsPerFrame) { // ...then update the frame, and... animation.CurrentFrame++; // ...if the current frame is the last, ... if (animation.CurrentFrame >= animation.Animation.NumFrames) { if (animation.IsLooped) // ...and the animation is set to wrap... { // ...then update the frame # & the times looped. animation.CurrentFrame = 0; animation.TimesLooped++; } else // if not, the animation is done, and should be removed soon. { toReturn = new CompletedState(animation); animation.CurrentFrame--; // To avoid IndexOutOfBounds error in draw func. } } // Remove one "frame" worth of time animation.timeSinceLastFrameChange -= animation.SecondsPerFrame; // If the animation isn't allowed to skip animation frames, then break out of the loop. if (!animation.CanSkipFrames) { break; } } } else { toReturn = new PausedState(animation); } return(toReturn); }; Draw = (SpriteBatch batch) => { if (animation.Posit == null) { if (animation.Animation.UseEachFramesDrawEffects) { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch); } else { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch, animation.Animation.DrawEffects); } } else { if (animation.Animation.UseEachFramesDrawEffects) { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch, null, animation.Posit.Value); } else { animation.AnimationFrames[animation.CurrentFrame].DrawSprite(batch, animation.Animation.DrawEffects, animation.Posit.Value); } } //throw new NotImplementedException(); }; }