Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Xna.Framework.Storage;
- namespace XNA_Game_Try_2
- {
- public class AnimatedSprite
- {
- public Texture2D Texture { get; set; }
- public int Rows { get; set; }
- public int Columns { get; set; }
- private int currentFrame;
- private int totalFrames;
- public AnimatedSprite(Texture2D texture, int rows, int columns)
- {
- Texture = texture;
- Rows = rows;
- Columns = columns;
- currentFrame = 0;
- totalFrames = Rows*Columns;
- }
- public void Update()
- {
- currentFrame++;
- if (currentFrame == totalFrames)
- currentFrame = 0;
- }
- public void Draw(SpriteBatch spriteBatch, Vector2 location, string xScale)
- {
- int width = Texture.Width / Columns;
- int height = Texture.Height / Rows;
- int row = (int)((float)currentFrame / (float)Columns);
- int column = currentFrame % Columns;
- Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height);
- Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height);
- spriteBatch.Begin();
- if (xScale == "Right")
- {
- spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
- }
- else if (xScale == "Left")
- {
- spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White, 113.1f, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0);
- }
- else if (xScale == "JumpRight")
- {
- spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
- }
- else if (xScale == "JumpLeft")
- {
- spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White, 113.1f, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0);
- }
- spriteBatch.End();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment