Advertisement
shineJazama

1

Feb 21st, 2025
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. ** sprite class i'm using for project **
  2.  
  3. class Sprite
  4. {
  5. public Texture2D image; // image representing sprite
  6. public Vector2 position; // position for sprite
  7.  
  8. public Rectangle Rect // physical representation of sprite
  9. {
  10. get
  11. {
  12. return new Rectangle((int)this.position.X, (int)this.position.Y, this.image.Width, this.image.Height); // getter returns rectangle based on images size and xy position
  13. }
  14. }
  15.  
  16. public Sprite(Texture2D image, Vector2 position)
  17. {
  18. this.image = image;
  19. this.position = position;
  20. }
  21.  
  22. public void Draw(SpriteBatch spriteBatch) // call this to draw the sprite to the screen, takes a spritebatch as an argument
  23. {
  24. spriteBatch.Draw(this.image, Rect, Color.White)
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement