How to use Game Window in XNA


HTML clipboard

GameWindow is the object which shows XNA Games/Applications inside.And as every game or application has a window,GameWindow object is a must-have in XNA.

Lets take a look at its structure then make an example how to use it:

We can allow user to resize the GameWindow setting AllowUserResizing to true:

GameWindow1.gif


We can transite from windowed mode to full screen or full screen to windowed mode using BeginDeviceChange function:

GameWindow2.gif

Using ClientBounds you can get X,Y,Width and Height values of the GameWindow:

GameWindow3.gif

On ClientSizeChanged function if the user or dynamically in code the Client Size(Width or Height) changes,then this event raises:

GameWindow4.gif

To get the current Orientation use CurrentOrientation.This is much more useful in Windows Phone or ZUNE games:

GameWindow5.gif

To change screen devices use EndScreenDeviceChange:

GameWindow6.gif

Window.Handle is very useful.It helps you to add anything on the specified handle.You can work it like a Windows Forms if you want.

GameWindow7.gif

This event raises when user or device changes its orientation.More useful in Windows Phone and Zune Device:

GameWindow8.gif

You can get Screen Device Name using ScreenDeviceName:

GameWindow9.gif

After changing the screen device,this event raises:

GameWindow10.gif

Title is as you well know is the header of the GameWindow.You can write anything there:

GameWindow11.gif

And now lets make a sample on how to use it:

AllowUserResizing:

When we dont set it true,it look like we cant resize it.But if you set it to true using:

Window.AllowUserResizing = true;

GameWindow12.gif

To get the Orientation of the Window use:

Window.Title= Window.CurrentOrientation.ToString();

GameWindow13.gif


You can see a "Default" value in the Windows Title property.

Lets have a look at which Orientations are there in a DisplayOrientation:

Default: it is the default orientation when first run.

LanscapeLeft: The display is rotated counterclockwise ninety degrees into a landscape presentation, where the width is greater than the height.

LandscapeRight: The display is rotated clockwise ninety degrees into a landscape presentation, where the width is greater than the height.

Portrait: The orientation is a portrait presentation, where the height is greater than the width.

To get screen device name use:

Window.Title = Window.ScreenDeviceName;

GameWindow14.gif


 

erver'>

Similar Articles