amitsly1

Untitled

Oct 4th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Xna.Framework.Storage;
  12.  
  13.  
  14. namespace XNA_Game_Try_2
  15. {
  16. public class AnimatedSprite
  17. {
  18. public Texture2D Texture { get; set; }
  19. public int Rows { get; set; }
  20. public int Columns { get; set; }
  21. private int currentFrame;
  22. private int totalFrames;
  23.  
  24.  
  25.  
  26. public AnimatedSprite(Texture2D texture, int rows, int columns)
  27. {
  28. Texture = texture;
  29. Rows = rows;
  30. Columns = columns;
  31. currentFrame = 0;
  32. totalFrames = Rows*Columns;
  33. }
  34.  
  35.  
  36. public void Update()
  37. {
  38. currentFrame++;
  39. if (currentFrame == totalFrames)
  40. currentFrame = 0;
  41. }
  42.  
  43.  
  44. public void Draw(SpriteBatch spriteBatch, Vector2 location, string xScale)
  45. {
  46. int width = Texture.Width / Columns;
  47. int height = Texture.Height / Rows;
  48. int row = (int)((float)currentFrame / (float)Columns);
  49. int column = currentFrame % Columns;
  50.  
  51. Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height);
  52. Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height);
  53.  
  54. spriteBatch.Begin();
  55. if (xScale == "Right")
  56. {
  57. spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
  58. }
  59. else if (xScale == "Left")
  60. {
  61. spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White, 113.1f, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0);
  62. }
  63. else if (xScale == "JumpRight")
  64. {
  65. spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
  66. }
  67. else if (xScale == "JumpLeft")
  68. {
  69. spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White, 113.1f, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0);
  70. }
  71.  
  72.  
  73. spriteBatch.End();
  74.  
  75. }
  76.  
  77.  
  78.  
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment