TheGadgetCatTumblr

Sprite Class (Update 1/25/12)

Jan 26th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace CatTetris
  7. {
  8.     using System;
  9.     using System.Collections.Generic;
  10.     using System.Linq;
  11.     using System.Text;
  12.     using Microsoft.Xna.Framework;
  13.     using Microsoft.Xna.Framework.Content;
  14.     using Microsoft.Xna.Framework.Graphics;
  15.  
  16.  
  17.         public class Sprite
  18.         {
  19.             public Vector2 Position = new Vector2(0, 0);
  20.             public Vector2 offset = new Vector2(0, 0);
  21.             public Texture2D mSpriteTexture;
  22.             public string AssetName;
  23.             public Rectangle Size;
  24.             private float mScale = 1.0f;
  25.  
  26.             private Texture2D pixel;
  27.  
  28.             public Vector2 origin;
  29.  
  30.             public Sprite()
  31.             {
  32.  
  33.             }
  34.  
  35.             //Load content
  36.             public void LoadContent(ContentManager theContentManager, String theAssetName)
  37.             {
  38.                 mSpriteTexture = theContentManager.Load<Texture2D>(theAssetName);
  39.                 AssetName = theAssetName;
  40.  
  41.                 pixel = theContentManager.Load<Texture2D>("pixel");
  42.  
  43.                 Size = new Rectangle((int)Position.X, (int)Position.Y, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale));
  44.             }
  45.  
  46.             public void Update(Vector2 position, Vector2 offset)
  47.             {
  48.                 Position = (position + offset);
  49.             }
  50.  
  51.             public void Draw(SpriteBatch theSpriteBatch)
  52.             {
  53.                 theSpriteBatch.Draw(mSpriteTexture, Position,
  54.                     Size, Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);
  55.            
  56.                 //draw a "pixel" texture at the origin of the sprite
  57.                 //theSpriteBatch.Draw(pixel, Position, new Rectangle(0,0,10,10), Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);
  58.             }
  59.  
  60.             public float Scale
  61.             {
  62.                 get { return mScale; }
  63.                 set
  64.                 {
  65.                     mScale = value;
  66.                     Size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale));
  67.                 }
  68.             }
  69.             public Rectangle BoundingBox()
  70.             {
  71.                  return new Rectangle(
  72.                  (int)Position.X + 1,
  73.                  (int)Position.Y + 1,
  74.                  mSpriteTexture.Width + 1,
  75.                  mSpriteTexture.Height + 1);
  76.             }
  77.  
  78.          
  79.         }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment