Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace CPI311.Game_Engine
- {
- public class AnimatedSprite : Sprite
- {
- public int FrameWidth;
- public int FrameHeight;
- public int Rows;
- public int Columns;
- public double Speed;
- public double delta = 0;
- public int FrameRow = 0;
- public int FrameColumn = 0;
- public AnimatedSprite(Texture2D texture, int frameWidth, int frameHeight, int rows, int columns, double speed) : base(texture)
- {
- FrameWidth = frameWidth;
- FrameHeight = frameHeight;
- Rows = rows;
- Columns = columns;
- Speed = speed;
- }
- public void Update(GameTime gameTime)
- {
- delta += gameTime.ElapsedGameTime.Milliseconds;
- if(delta >= 1/Speed * 1000)
- {
- delta = 0;
- NextFrame();
- }
- }
- public void NextFrame()
- {
- if (FrameColumn < Columns-1)
- FrameColumn += 1;
- else
- {
- if(FrameRow < Rows-1)
- {
- FrameColumn = 0;
- FrameRow += 1;
- }
- else
- {
- FrameColumn = 0;
- FrameRow = 0;
- }
- }
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- Rectangle source = new Rectangle(FrameColumn*FrameWidth, FrameRow*FrameHeight, FrameWidth, FrameHeight);
- spriteBatch.Draw(Texture, Position, source, Color,
- Rotation, Origin, Scale, Effects, Layer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement