using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace WindowsGame1
{
///
/// This is the class which will be used to draw sprites to the screen.
///
class EntitySprite : DrawableGameComponent
{
///
/// The position of the sprite on the screen. Defaults to Vecter2.Zero
///
protected Vector2 m_Position = Vector2.Zero;
public Vector2 Position
{
get { return m_Position; }
set { m_Position = value; }
}
///
/// The SpriteBatch object used to draw the sprite. Defaults to null. Will be ignored if the SpriteBatch is passed as a draw
/// parameter.
///
protected SpriteBatch m_SpriteBatch = null;
public SpriteBatch SpriteBatch
{
get { return m_SpriteBatch; }
set { m_SpriteBatch = value; }
}
///
/// The Texture that the sprite will use.
///
protected Texture2D m_Texture;
public Texture2D Texture
{
get { return m_Texture; }
set { m_Texture = value; }
}
///
/// The Color to be applied to the sprite. Defaults to Color.White.
///
protected Color m_Color = Color.White;
public Color Color
{
get { return m_Color; }
set { m_Color = value; }
}
///
/// The origin of rotation of the sprite. Default is Upper left (Vector.Zero).
///
protected Vector2 m_RotationOrigin = Vector2.Zero;
public Vector2 RotationOrigin
{
get { return m_RotationOrigin; }
set { m_RotationOrigin = value; }
}
///
/// The amount of rotation to apply to the sprite. Defaults to 0
///
protected float m_Rotation = 0;
public float Rotation
{
get { return m_Rotation; }
set { m_Rotation = value; }
}
///
/// A scalar to apply to the sprite. Defaults to 1
///
protected float m_Scale = 1;
public float Scale
{
get { return m_Scale; }
set { m_Scale = value; }
}
///
/// The Layer Depth of the sprite. This affects what is drawn in front of it. 0 = front, 1 = back.
/// Defaults to 0
///
protected float m_LayerDepth = 0;
public float LayerDepth
{
get { return m_LayerDepth; }
set { m_LayerDepth = value; }
}
///
/// Default Constructor
///
/// The game the sprite is associated with.
public EntitySprite(Game p_Game)
: base(p_Game)
{ }
///
/// Constructor
///
/// The game the sprite is associated with.
/// The texture that the sprite will use.
public EntitySprite(Game p_Game, Texture2D p_Texture) : base(p_Game)
{
m_Texture = p_Texture;
}
///
/// Constructor
///
/// The game object that the sprite is associated with.
/// The Texture2D that the sprite will use.
/// The Position of the sprite on the screen.
public EntitySprite(Game p_Game, Texture2D p_Texture, Vector2 p_Position)
: base(p_Game)
{
m_Texture = p_Texture;
m_Position = p_Position;
}
///
/// The draw method that will be called by XNA during the Draw cycle.
///
/// The current game time. Passed in by XNA.
public override void Draw(GameTime gameTime)
{
GraphicsDevice.RenderState.DepthBufferEnable = true;
GraphicsDevice.RenderState.DepthBufferFunction = CompareFunction.Always;
GraphicsDevice.RenderState.FillMode = FillMode.Solid;
m_SpriteBatch.Begin();
m_SpriteBatch.Draw(m_Texture, m_Position, null, m_Color, m_Rotation, m_RotationOrigin, m_Scale, SpriteEffects.None, m_LayerDepth);
m_SpriteBatch.End();
}
}
}