Export (0) Print
Expand All

Game.Draw Method

Called when the game determines it is time to draw a frame. Override this method with game-specific rendering code.

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

protected virtual void Draw (
         GameTime gameTime
)

Parameters

gameTime
Time passed since the last call to Draw.

Update and Draw are called at different rates depending on whether IsFixedTimeStep is true or false. If IsFixedTimeStep is false, Update and Draw will be called sequentially as often as possible. If IsFixedTimeStep is true, Update will be called at the interval specified in TargetElapsedTime, while Draw will continue to be called as often as possible. For more information on fixed-step and variable-step game loops, see Application Model Overview.

Bb196422.caution(en-US,XNAGameStudio.20).gifCaution

In the Draw method of an Xbox 360 game, vertex buffers, index buffers, and textures should not be written using SetData when they are intended to be used for rendering. This condition may lead to graphics corruption or crashes. To avoid this potential issue, use DrawUserPrimitives or DrawUserIndexedPrimitives as the preferred alternative to VertexBuffer.SetData for dynamic vertex generation.

This is because, in cases where the size of the back buffer and depth stencil buffer exceed the size of the Xbox 360 10 MB of embedded memory (EDRAM), predicated tiling is utilized on this platform to compensate for the additional memory requirements. Predicated tiling is a process by which scene rendering is performed multiple times on subsections of the final render target dimensions.

When predicated tiling has been triggered, the drawing commands contained in the Draw function are not submitted until Present is called. (Note that Draw implicitly calls Present at the end of this method.) In this case, these resources are not available for modification until the GPU is finished with presenting the entire frame.

In classes that derive from Game, it is necessary to call base.Draw in Draw to enumerate through any graphics components that have been added to Components and call their Initialize methods.

protected override void Draw( GameTime gameTime )
{
  base.Draw( gameTime );
}
    

Xbox 360, Windows XP SP2, Windows Vista

Community Additions

ADD
Show:
© 2014 Microsoft