Sprite.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Tutorial023.Sprites
  9. {
  10. public class Sprite : Component
  11. {
  12. protected float _layer { get; set; }
  13. protected Texture2D _texture;
  14. public float Layer
  15. {
  16. get { return _layer; }
  17. set
  18. {
  19. _layer = value;
  20. }
  21. }
  22. public Vector2 Position;
  23. public Rectangle Rectangle
  24. {
  25. get
  26. {
  27. return new Rectangle((int)Position.X, (int)Position.Y, _texture.Width, _texture.Height);
  28. }
  29. }
  30. public Sprite(Texture2D texture)
  31. {
  32. _texture = texture;
  33. }
  34. public override void Update(GameTime gameTime)
  35. {
  36. }
  37. public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
  38. {
  39. spriteBatch.Draw(_texture, Position, null, Color.White, 0, new Vector2(0, 0), 1f, SpriteEffects.None, Layer);
  40. }
  41. }
  42. }