#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
#endregion
namespace Tutorial2
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public partial class Sprite : Microsoft.Xna.Framework.DrawableGameComponent
{
private ContentManager manager;
private SpriteBatch spriteBatch;
private Texture2D texture;
public Sprite(Game game)
: base(game)
{
// TODO: Construct any child components here
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
// TODO: Add your initialization code here
base.Initialize();
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
base.LoadGraphicsContent(loadAllContent);
if (loadAllContent)
{
manager = new ContentManager(this.Game.Services);
spriteBatch = new SpriteBatch(this.GraphicsDevice);
texture = manager.Load<Texture2D>("texture1");
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
base.UnloadGraphicsContent(unloadAllContent);
if (unloadAllContent)
{
manager.Unload();
spriteBatch.Dispose();
texture.Dispose();
}
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
spriteBatch.Begin();
spriteBatch.Draw(texture, new Rectangle(X, Y, 24, 24), Color.White);
spriteBatch.End();
}
public int X
{
get
{
return X;
}
set
{
X = value;
}
}
public int Y
{
get
{
return Y;
}
set
{
Y = value;
}
}
}
}