Afficher et animer des images : les sprites
CHAPITRE 3
49
using Microsoft.Xna.Framework.Storage;
namespace PremierProjetXNA
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Sprite personnage;
float speed;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
speed = 0.2f;
}
protected override void Initialize()
{
personnage = new Sprite(100, 100);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
personnage.LoadContent(Content, "personnage");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
➥ButtonState.Pressed)
this.Exit();
personnage.Update(new Vector2(gameTime.ElapsedGameTime.Milliseconds *
➥speed, gameTime.ElapsedGameTime.Milliseconds * speed));
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
=Labat FM.book Page 49 Vendredi, 19. juin 2009 4:01 16
CHAPITRE 3
49
using Microsoft.Xna.Framework.Storage;
namespace PremierProjetXNA
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Sprite personnage;
float speed;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
speed = 0.2f;
}
protected override void Initialize()
{
personnage = new Sprite(100, 100);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
personnage.LoadContent(Content, "personnage");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
➥ButtonState.Pressed)
this.Exit();
personnage.Update(new Vector2(gameTime.ElapsedGameTime.Milliseconds *
➥speed, gameTime.ElapsedGameTime.Milliseconds * speed));
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
=Labat FM.book Page 49 Vendredi, 19. juin 2009 4:01 16
