using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class SpriteGameObject : GameObject { protected Texture2D sprite; protected bool visible; public SpriteGameObject(GameWorld gameWorld, string assetname, int layer = 0, string id = "") : base(layer, id) { sprite = gameWorld.ResourceManager.getSprite(assetname); color = Color.White; } public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { if (visible && sprite != null) spriteBatch.Draw(sprite, this.GlobalPosition, color); } public override void Reset() { base.Reset(); visible = true; } public Texture2D Sprite { get { return sprite; } } public Vector2 Center { get { if (sprite != null) return new Vector2(sprite.Width, sprite.Height) / 2; else return Vector2.Zero; } } public bool Visible { get { return visible; } set { visible = value; } } public override Rectangle BoundingRectangle { get { if (sprite != null) return new Rectangle((int)GlobalPosition.X, (int)GlobalPosition.Y, sprite.Width, sprite.Height); else return new Rectangle((int)GlobalPosition.X, (int)GlobalPosition.Y, 0, 0); } } }