Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace Breakout
- {
- class CSprite
- {
- private float halfHeight, halfWidth;
- private Rectangle subRectangle = new Rectangle();
- private Color color = new Color(1.0f, 1.0f, 1.0f);
- public Color Color
- {
- set { color = value; }
- }
- private Vector2 position = new Vector2(400, 240);
- public Vector2 Position
- {
- get { return position; }
- set { position = value; }
- }
- private Texture2D image;
- public Texture2D Image
- {
- set
- {
- image = value;
- subRectangle.X = 0;
- subRectangle.Y = 0;
- subRectangle.Width = image.Width;
- subRectangle.Height = image.Height;
- halfWidth = subRectangle.Width / 2;
- halfHeight = subRectangle.Height / 2;
- }
- }
- public float Width
- {
- get { return subRectangle.Width; }
- }
- public float Height
- {
- get { return subRectangle.Height; }
- }
- public void SetSubRect(Rectangle subRectangle)
- {
- this.subRectangle = subRectangle;
- halfWidth = this.subRectangle.Width / 2;
- halfHeight = this.subRectangle.Height / 2;
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- spriteBatch.Draw(image, new Vector2(position.X - halfWidth, position.Y - halfHeight), subRectangle, color);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement