Développement XNA pour la XBox et le PC
104
La classe Sprite qui prend en charge une position de type Vector2
class Sprite
{
Vector2 position;
public Vector2 Position
{
get { return position; }
set { position = value; }
}
Texture2D texture;
public Texture2D Texture
{
get { return texture; }
}
Rectangle? sourceRectangle = null;
public Rectangle? SourceRectangle
{
get { return sourceRectangle; }
set { sourceRectangle = value; }
}
public Sprite(Vector2 position)
{
this.position = position;
}
public Sprite(Vector2 position, Rectangle? sourceRectangle)
{
this.position = position;
this.sourceRectangle = sourceRectangle;
}
public Sprite(float x, float y, Rectangle? sourceRectangle)
{
position = new Vector2(x, y);
this.sourceRectangle = sourceRectangle;
}
public void LoadContent(ContentManager content, string assetName)
{
texture = content.Load(assetName);
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, sourceRectangle, Color.White);
}
}
=Labat FM.book Page 104 Vendredi, 19. juin 2009 4:01 16
Précédent

- 125/366

Suivant