Ejemplo n.º 1
0
 public void Reset()
 {
     CurrentDirection = SpriteAnimDirection.Forward;
     CurrentFrame     = 0;
     CurrentFrameTime = 0;
     State            = SpriteAnimState.Paused;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 4
0
 public void Play()
 {
     State = SpriteAnimState.Playing;
 }
Ejemplo n.º 5
0
 public void Pause()
 {
     State = SpriteAnimState.Paused;
 }
Ejemplo n.º 6
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 if (Loop)
                    {
                        CurrentFrame = 0;
                    }
                    else
                    {
                        State = SpriteAnimState.Paused;
                        CurrentFrame--;
                    }
                }
                break;

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 7
0
 public void Pause()
 {
     State = SpriteAnimState.Paused;
 }
Ejemplo n.º 8
0
 public void Play()
 {
     State = SpriteAnimState.Playing;
 }
Ejemplo n.º 9
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 if (Loop) CurrentFrame = 0;
                        else { State = SpriteAnimState.Paused;
                            CurrentFrame--;
                        }
                    }
                    break;
                case SpriteAnimDirection.Reverse:
                    CurrentFrame--;
                    if (CurrentFrame == -1)
                    {
                        if (PingPong && NumFrames > 1)
                        {
                            CurrentDirection = SpriteAnimDirection.Forward;
                            CurrentFrame = 1;
                        }
                        else if(Loop) CurrentFrame = NumFrames-1;
                        else
                        {
                            State = SpriteAnimState.Paused;
                            CurrentFrame--;
                        }

                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 10
0
 public void Reset()
 {
     CurrentDirection = SpriteAnimDirection.Forward;
     CurrentFrame = 0;
     CurrentFrameTime = 0;
     State = SpriteAnimState.Paused;
 }