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)
Syntax
public int DrawOrder { get; set; }
Property Value
Order in which the component should be drawn.
Remarks
This value can be any integer. Components in the GameComponentCollection are drawn in ascending order based on their DrawOrder.
Example
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);
thirdGameComponent.DrawOrder = 3;
game.Components.Add(thirdGameComponent);
MyDrawableGameComponent firstGameComponent = new MyDrawableGameComponent(game);
firstGameComponent.DrawOrder = 1;
game.Components.Add(firstGameComponent);
MyDrawableGameComponent secondGameComponent = new MyDrawableGameComponent(game);
secondGameComponent.DrawOrder = 2;
game.Components.Add(secondGameComponent);
See Also
Reference
DrawableGameComponent Class
DrawableGameComponent Members
Microsoft.Xna.Framework Namespace
Platforms
Xbox 360, Windows 7, Windows Vista, Windows XP