Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3.  
  4. namespace Breakout
  5. {
  6.     class CSprite
  7.     {
  8.         private float halfHeight, halfWidth;
  9.         private Rectangle subRectangle = new Rectangle();
  10.  
  11.         private Color color = new Color(1.0f, 1.0f, 1.0f);
  12.         public Color Color
  13.         {
  14.             set { color = value; }
  15.         }
  16.  
  17.         private Vector2 position = new Vector2(400, 240);
  18.         public Vector2 Position
  19.         {
  20.              get { return position; }
  21.              set { position = value; }
  22.         }
  23.  
  24.         private Texture2D image;
  25.         public Texture2D Image
  26.         {
  27.             set
  28.             {
  29.                 image = value;
  30.  
  31.                 subRectangle.X = 0;
  32.                 subRectangle.Y = 0;
  33.                 subRectangle.Width = image.Width;
  34.                 subRectangle.Height = image.Height;
  35.  
  36.                 halfWidth = subRectangle.Width / 2;
  37.                 halfHeight = subRectangle.Height / 2;
  38.             }
  39.         }
  40.  
  41.         public float Width
  42.         {
  43.             get { return subRectangle.Width; }
  44.         }
  45.  
  46.         public float Height
  47.         {
  48.             get { return subRectangle.Height; }
  49.         }
  50.  
  51.         public void SetSubRect(Rectangle subRectangle)
  52.         {
  53.             this.subRectangle = subRectangle;
  54.  
  55.             halfWidth = this.subRectangle.Width / 2;
  56.             halfHeight = this.subRectangle.Height / 2;
  57.         }
  58.  
  59.         public void Draw(SpriteBatch spriteBatch)
  60.         {
  61.             spriteBatch.Draw(image, new Vector2(position.X - halfWidth, position.Y - halfHeight), subRectangle, color);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement