Sprite.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 Tutorial029.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, (int)(_texture.Width * Scale), (int)(_texture.Height * Scale));
  28. }
  29. }
  30. public float Scale { get; set; } = 1f;
  31. public Sprite(Texture2D texture)
  32. {
  33. _texture = texture;
  34. }
  35. public override void Update(GameTime gameTime)
  36. {
  37. }
  38. public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
  39. {
  40. spriteBatch.Draw(_texture, Position, null, Color.White, 0, new Vector2(0, 0), Scale, SpriteEffects.None, Layer);
  41. }
  42. }
  43. }