//Sprite.cs #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 { /// /// This is a game component that implements IUpdateable. /// public partial class Sprite : Microsoft.Xna.Framework.DrawableGameComponent { private ContentManager manager; private SpriteBatch spriteBatch; private Texture2D texture; private int m_x, m_y = 0; public Sprite(Game game) : base(game) { // TODO: Construct any child components here } /// /// 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. /// 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("texture1"); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { base.UnloadGraphicsContent(unloadAllContent); if (unloadAllContent) manager.Unload(); spriteBatch.Dispose(); texture.Dispose(); } /// /// Allows the game component to update itself. /// /// Provides a snapshot of timing values. public override void Update(GameTime gameTime) { // TODO: Add your update code here base.Update(gameTime); } public override void Draw(GameTime gameTime) { spriteBatch.Begin(); spriteBatch.Draw(texture, new Rectangle(X, Y, 24, 24), Color.White); spriteBatch.End(); base.Draw(gameTime); } public int X { get { return X; } set { X = value; } } public int Y { get { return Y; } set { Y = value; } } } }