Beispiel #1
0
 public void Reset()
 {
     CurrentDirection = SpriteAnimDirection.Forward;
     CurrentFrame     = 0;
     CurrentFrameTime = 0;
     State            = SpriteAnimState.Paused;
 }
Beispiel #2
0
        public void Update(GameTime gameTime)
        {
            if (State != SpriteAnimState.Playing)
            {
                return;
            }

            CurrentFrameTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (CurrentFrameTime < TargetFrameTime)
            {
                return;
            }

            CurrentFrameTime = 0;

            switch (CurrentDirection)
            {
            case SpriteAnimDirection.Forward:
                CurrentFrame++;
                if (CurrentFrame == NumFrames)
                {
                    if (PingPong && NumFrames > 1)
                    {
                        CurrentDirection = SpriteAnimDirection.Reverse;
                        CurrentFrame    -= 2;
                    }
                    else
                    {
                        CurrentFrame = 0;
                    }
                }
                break;

            case SpriteAnimDirection.Reverse:
                CurrentFrame--;
                if (CurrentFrame == -1)
                {
                    if (PingPong && NumFrames > 1)
                    {
                        CurrentDirection = SpriteAnimDirection.Forward;
                        CurrentFrame     = 1;
                    }
                    else
                    {
                        CurrentFrame = NumFrames - 1;
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #3
0
 public SpriteAnim(Texture2D sheet, int row, int numframes, int width, int height, double frametime)
 {
     SpriteSheet = sheet;
     Offset = new Vector2(sheet.Width,sheet.Height)/2f;
     NumFrames = numframes;
     SheetRow = row;
     CellWidth = width;
     CellHeight = height;
     CurrentFrame = 0;
     CurrentFrameTime = 0;
     TargetFrameTime = frametime;
     Loop = true;
     PingPong = false;
     CurrentDirection = SpriteAnimDirection.Forward;
     State = SpriteAnimState.Paused;
 }
Beispiel #4
0
 public SpriteAnim(Texture2D sheet, int row, int numframes, int width, int height, double frametime)
 {
     SpriteSheet      = sheet;
     Offset           = new Vector2(sheet.Width, sheet.Height) / 2f;
     NumFrames        = numframes;
     SheetRow         = row;
     CellWidth        = width;
     CellHeight       = height;
     CurrentFrame     = 0;
     CurrentFrameTime = 0;
     TargetFrameTime  = frametime;
     Loop             = true;
     PingPong         = false;
     CurrentDirection = SpriteAnimDirection.Forward;
     State            = SpriteAnimState.Paused;
 }
Beispiel #5
0
        public void Update(GameTime gameTime)
        {
            if (State != SpriteAnimState.Playing) return;

            CurrentFrameTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (CurrentFrameTime < TargetFrameTime) return;

            CurrentFrameTime = 0;

            switch(CurrentDirection)
            {
                case SpriteAnimDirection.Forward:
                    CurrentFrame++;
                    if (CurrentFrame == NumFrames)
                    {
                        if (PingPong && NumFrames > 1)
                        {
                            CurrentDirection = SpriteAnimDirection.Reverse;
                            CurrentFrame -= 2;
                        }
                        else CurrentFrame = 0;
                    }
                    break;
                case SpriteAnimDirection.Reverse:
                    CurrentFrame--;
                    if (CurrentFrame == -1)
                    {
                        if (PingPong && NumFrames > 1)
                        {
                            CurrentDirection = SpriteAnimDirection.Forward;
                            CurrentFrame = 1;
                        }
                        else CurrentFrame = NumFrames-1;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #6
0
 public void Reset()
 {
     CurrentDirection = SpriteAnimDirection.Forward;
     CurrentFrame = 0;
     CurrentFrameTime = 0;
 }
Beispiel #7
0
 public void Reset()
 {
     CurrentDirection = SpriteAnimDirection.Forward;
     CurrentFrame     = 0;
     CurrentFrameTime = 0;
 }
Beispiel #8
0
 public void Reset()
 {
     CurrentDirection = SpriteAnimDirection.Forward;
     CurrentFrame = 0;
     CurrentFrameTime = 0;
     State = SpriteAnimState.Paused;
 }