DrawableGameComponent.DrawOrder Property

Order in which the component should be drawn, relative to other components that are in the same GameComponentCollection.

Namespace: Microsoft.Xna.Framework
Assembly: Microsoft.Xna.Framework.Game (in microsoft.xna.framework.game.dll)

public int DrawOrder { get; set; }

Property Value

Order in which the component should be drawn.

This value can be any integer. Components in the GameComponentCollection are drawn in ascending order based on their DrawOrder.

In this example, the three components are added to a GameComponentCollection, and the DrawOrder of each component is explicitly set to control the drawing order of each component regardless of the order it was added to the GameComponentCollection. MyDrawableGameComponent is a class which derives from DrawableGameComponent, and game is an instance of Game.

  MyDrawableGameComponent thirdGameComponent = new MyDrawableGameComponent(game);
  d3.DrawOrder = 3;
  MyDrawableGameComponent firstGameComponent = new MyDrawableGameComponent(game);
  d1.DrawOrder = 1;

  MyDrawableGameComponent secondGameComponent = new MyDrawableGameComponent(game);
  d2.DrawOrder = 2;

Xbox 360, Windows XP SP2, Windows Vista