Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CatTetris
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- public class Sprite
- {
- public Vector2 Position = new Vector2(0, 0);
- public Vector2 offset = new Vector2(0, 0);
- public Texture2D mSpriteTexture;
- public string AssetName;
- public Rectangle Size;
- private float mScale = 1.0f;
- private Texture2D pixel;
- public Vector2 origin;
- public Sprite()
- {
- }
- //Load content
- public void LoadContent(ContentManager theContentManager, String theAssetName)
- {
- mSpriteTexture = theContentManager.Load<Texture2D>(theAssetName);
- AssetName = theAssetName;
- pixel = theContentManager.Load<Texture2D>("pixel");
- Size = new Rectangle((int)Position.X, (int)Position.Y, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale));
- }
- public void Update(Vector2 position, Vector2 offset)
- {
- Position = (position + offset);
- }
- public void Draw(SpriteBatch theSpriteBatch)
- {
- theSpriteBatch.Draw(mSpriteTexture, Position,
- Size, Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);
- //draw a "pixel" texture at the origin of the sprite
- //theSpriteBatch.Draw(pixel, Position, new Rectangle(0,0,10,10), Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);
- }
- public float Scale
- {
- get { return mScale; }
- set
- {
- mScale = value;
- Size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale));
- }
- }
- public Rectangle BoundingBox()
- {
- return new Rectangle(
- (int)Position.X + 1,
- (int)Position.Y + 1,
- mSpriteTexture.Width + 1,
- mSpriteTexture.Height + 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment