Développement XNA pour la XBox et le PC
44
Heureusement, la méthode Update() reçoit un objet GameTime comme paramètre. Grâce à
ce dernier, vous avez accès au nombre de millisecondes écoulées depuis le dernier appel
à Update.
Au niveau du code, voici ce que cela donne :
ballePosition += (balleDirection * vitesse * gameTime.ElapsedGameTime.Milliseconds);
Voici le code source récapitulant les points vus précédemment :
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Chap3
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D balleTexture;
Vector2 ballePosition;
Vector2 ballePosition2;
Vector2 balleDirection;
float vitesse;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
ballePosition = new Vector2(10, 20);
balleDirection = new Vector2(-1, 1);
vitesse = 0.2f;
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
balleTexture = Content.Load("balle");
ballePosition2 = new Vector2(graphics.PreferredBackBufferWidth /
➥2 - balleTexture.Width / 2
, graphics.PreferredBackBufferHeight / 2 - balleTexture.Height / 2);
}
=Labat FM.book Page 44 Vendredi, 19. juin 2009 4:01 16
44
Heureusement, la méthode Update() reçoit un objet GameTime comme paramètre. Grâce à
ce dernier, vous avez accès au nombre de millisecondes écoulées depuis le dernier appel
à Update.
Au niveau du code, voici ce que cela donne :
ballePosition += (balleDirection * vitesse * gameTime.ElapsedGameTime.Milliseconds);
Voici le code source récapitulant les points vus précédemment :
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Chap3
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D balleTexture;
Vector2 ballePosition;
Vector2 ballePosition2;
Vector2 balleDirection;
float vitesse;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
ballePosition = new Vector2(10, 20);
balleDirection = new Vector2(-1, 1);
vitesse = 0.2f;
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
balleTexture = Content.Load
ballePosition2 = new Vector2(graphics.PreferredBackBufferWidth /
➥2 - balleTexture.Width / 2
, graphics.PreferredBackBufferHeight / 2 - balleTexture.Height / 2);
}
=Labat FM.book Page 44 Vendredi, 19. juin 2009 4:01 16
