Enrichir les sprites : textures, défilement, transformation, animation
CHAPITRE 6
107
SpriteBatch spriteBatch;
Sprite sprite;
public ChapitreSix()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
ServiceHelper.Game = this;
Components.Add(new KeyboardService(this));
graphics.PreferredBackBufferWidth = 200;
graphics.PreferredBackBufferHeight = 300;
}
protected override void Initialize()
{
sprite = new Sprite(new Vector2(0, 0), new Rectangle(0, 0, 200, 300));
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
sprite.LoadContent(Content, "figure_6_11");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (ServiceHelper.Get().IsKeyDown(Keys.Right))
sprite.SourceRectangle = new Rectangle(sprite.SourceRectangle.Value.X
➥+ gameTime.ElapsedGameTime.Milliseconds / 10, 0, 200, 300);
if (ServiceHelper.Get().IsKeyDown(Keys.Left))
sprite.SourceRectangle = new Rectangle(sprite.SourceRectangle.Value.X
➥- gameTime.ElapsedGameTime.Milliseconds / 10, 0, 200, 300);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
sprite.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
=Labat FM.book Page 107 Vendredi, 19. juin 2009 4:01 16
Précédent

- 128/366

Suivant