Enrichir les sprites : textures, défilement, transformation, animation
CHAPITRE 6
129
public override void Initialize()
{
spriteBatch = new SpriteBatch(Game.GraphicsDevice);
spriteFont = Game.Content.Load("font");
}
protected override void LoadContent()
{
}
public override void Update(GameTime gameTime)
{
elapsedTime += gameTime.ElapsedGameTime;
if (elapsedTime > TimeSpan.FromSeconds(1))
{
elapsedTime -= TimeSpan.FromSeconds(1);
frameRate = frameCounter;
frameCounter = 0;
}
}
public override void Draw(GameTime gameTime)
{
frameCounter++;
spriteBatch.Begin();
spriteBatch.DrawString(spriteFont, frameRate.ToString() + " FPS", new
➥Vector2(0, 0), Color.White);
spriteBatch.End();
}
}
Pour l’utiliser, vous n’avez plus qu’à l’ajouter à la liste des composants.
public ChapitreSix()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
ServiceHelper.Game = this;
Components.Add(new KeyboardService(this));
Components.Add(new FPSComponent(this));
Avant de terminer ce chapitre, un dernier détail concernant l’optimisation de la taille des
polices de caractère. Pour celle chargée d’afficher le nombre de FPS, Shawn Hargreaves
propose de ne spécifier dans le fichier .spritefont que les caractères qui seront utilisés.



Arial
14
2

=Labat FM.book Page 129 Vendredi, 19. juin 2009 4:01 16
Précédent

- 150/366

Suivant