Sprite.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Tutorial006.Sprites
  10. {
  11. public class Sprite : ICloneable
  12. {
  13. protected Texture2D _texture;
  14. protected float _rotation;
  15. protected KeyboardState _currentKey;
  16. protected KeyboardState _previousKey;
  17. public Vector2 Position;
  18. public Vector2 Origin;
  19. public Vector2 Direction;
  20. public float RotationVelocity = 3f;
  21. public float LinearVelocity = 4f;
  22. public Sprite Parent;
  23. public float LifeSpan = 0f;
  24. public bool IsRemoved = false;
  25. public Sprite(Texture2D texture)
  26. {
  27. _texture = texture;
  28. // The default origin in the centre of the sprite
  29. Origin = new Vector2(_texture.Width / 2, _texture.Height / 2);
  30. }
  31. public virtual void Update(GameTime gameTime, List<Sprite> sprites)
  32. {
  33. }
  34. public virtual void Draw(SpriteBatch spriteBatch)
  35. {
  36. spriteBatch.Draw(_texture, Position, null, Color.White, _rotation, Origin, 1, SpriteEffects.None, 0);
  37. }
  38. public object Clone()
  39. {
  40. return this.MemberwiseClone();
  41. }
  42. }
  43. }