Sprite.cs 934 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. namespace Tutorial026.Sprites
  9. {
  10. public class Sprite : Component
  11. {
  12. protected Texture2D _texture;
  13. public Vector2 Position;
  14. public Rectangle Rectangle
  15. {
  16. get
  17. {
  18. return new Rectangle((int)Position.X, (int)Position.Y, _texture.Width, _texture.Height);
  19. }
  20. }
  21. public bool IsRemoved { get; set; }
  22. public Sprite(Texture2D texture)
  23. {
  24. _texture = texture;
  25. }
  26. public override void Update(GameTime gameTime)
  27. {
  28. }
  29. public virtual void OnCollide(Sprite sprite)
  30. {
  31. }
  32. public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
  33. {
  34. spriteBatch.Draw(_texture, Position, Color.White);
  35. }
  36. }
  37. }