Export (0) Print
Expand All

GraphicsDeviceManager Constructor

Creates a new GraphicsDeviceManager and registers it to handle the configuration and management of the graphics device for the specified Game.

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

public GraphicsDeviceManager (
         Game game
)

Parameters

game
Game the GraphicsDeviceManager should be associated with.

Exception typeCondition
ArgumentNullException The game parameter is null.
ArgumentException A graphics device manager has already been added to Services and registered as the graphics device manager for the application. The graphics device manager cannot be changed once it is set.

This constructor adds this GraphicsDeviceManager to the collection of game services that have been implicitly registered by adding them to the Game.Services property.

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

Although this constructor requires an instance of Game, if the application does not otherwise require an instance of Game it is often better to implement a the IGraphicsDeviceService and IGraphicsDeviceManager interfaces to provide the same services that would be provided by the GraphicsDeviceManager.

Custom behavior of the GraphicsDeviceManager can be achieved by deriving a class from GraphicsDeviceManager. For example, to allow only widescreen devices in full-screen mode the RankDevices method could be overridden to drop non-widescreen devices (see How To: Restrict Graphics Devices to Widescreen Aspect Ratios in Full-Screen Mode).

Or, if you are creating a 2D game, you might want to create a graphics device without a depth buffer. By adding an event handler for the PreparingDeviceSettings event to the GraphicsDeviceManager, you can control the PresentationParameters properties associated with the graphics device. In the example below, the event handler is named graphics_Settings_NoDepthBuffer.

graphics = new GraphicsDeviceManager(this);
graphics.PreparingDeviceSettings +=
    new EventHandler<PreparingDeviceSettingsEventArgs>(
                        graphics_Settings_NoDepthBuffer);

To ensure that no depth buffer is created, your event handler can set the EnableAutoDepthStencil property of the graphic device's PresentationParameters to false, as shown below.

void graphics_Settings_NoDepthBuffer(object sender, PreparingDeviceSettingsEventArgs e)
{
    e.GraphicsDeviceInformation.PresentationParameters.EnableAutoDepthStencil = false;
}

Xbox 360, Windows XP SP2, Windows Vista

Community Additions

ADD
Show:
© 2014 Microsoft