/* * StaticSprite.cs * Authors: August Zinsser, Adam Nabinger * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace MaritimeDefender { /// /// A very simple class for drawing a static image, designed to be used by HUD elements. Game objects should use Entity instead of this struct. /// public class StaticSprite { #region Fields /// /// The position and dimensions of the sprite /// internal Rectangle Location; /// /// The Z depth position for the sprite /// internal float ZDepth; /// /// The path name of the texture file to use /// internal readonly string TextureName; /// /// The texture that represents the sprite /// internal Texture2D Texture; /// /// The color tint of the sprite /// internal Color Tint; /// /// The position of the sprite /// internal Vector2 Origin; #endregion #region Creation /// /// Constructor /// /// The position and dimensions of the sprite /// The z dpeth of the sprite for draw order /// The path name of the texture file to use public StaticSprite(Rectangle location, float zDepth, string textureName) { Location = location; ZDepth = zDepth; TextureName = textureName; Tint = Color.White; } #endregion #region Management /// /// Loads in all necessary information for all content dependent objects /// /// Reference to the current content manager for loading in content public void LoadContent(ContentManager Content) { Texture = Content.Load(TextureName); Origin = new Vector2(Texture.Width * 0.5f, Texture.Height * 0.5f); } #endregion #region Render /// /// Draw to the given spritebatch /// /// Reference to the current sprite batch for rendering textures public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw( Texture, Location, null, Tint, 0f, Origin, SpriteEffects.None, ZDepth); } #endregion } }