namespace Key1
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
ContentManager content;
// Constructor
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
graphics.PreferredBackBufferWidth = 640; // Sets the screen size to 640x480
graphics.PreferredBackBufferHeight = 480;
// Here we would like switch the device to full screen mode if the user
// set the Solution configurations to Release mode
#if !DEBUG
// The IsFullScreen property can be used to Get or Set a value that indicates
// whether the device should start in full screen mode.
graphics.IsFullScreen = true;
#endif
// This property is FALSE by default and will not allow you to change the window size.
// Setting it will allow you to change windows size.
Window.AllowUserResizing = true;
// Setting up an event handler to monitor changed window size
Window.ClientSizeChanged += new System.EventHandler(UpdateFramebufferSize);
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
// TODO: Load any ResourceManagementMode.Automatic content
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent == true)
{
content.Unload();
}
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the default game to exit on Xbox 360 and Windows
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// KeyboardState - Represents a state of keystrokes recorded by a keyboard input device.
// Keyboard - A class dedicated to retrieve keystrokes fron the keyboard input device.
// Keys - An enumeration to Identify keys on the keyboard.
KeyboardState kState = Keyboard.GetState(); //Gets the current keyboard state.
if (kState.IsKeyDown(Keys.F))
{
// The GraphicsDeviceManager class has a built in function called
// ToggleFullScreen that will handle
graphics.ToggleFullScreen();
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.Orange);
base.Draw(gameTime);
}
/// <summary>
/// UDF -
/// This is called when the game window is resized. It sets the backbuffer
/// width and height to that of the windows client area size whenever the
/// window is resized by the user.
/// </summary>
/// <param name="sender">contains the details about the sender that called the event handler.</param>
/// <param name="e">parameter that will contain event data.</param>
void UpdateFramebufferSize(object sender, System.EventArgs e)
{
graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
}
}
}