SHARE
TWEET

Screen Toggle

SuperLemrick Mar 22nd, 2015 172 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace Screen_Toggle
  13. {
  14.     /// <summary>
  15.     /// This is the main type for your game
  16.     /// </summary>
  17.     public class ScreenToggle : Microsoft.Xna.Framework.Game
  18.     {
  19.  
  20.         Color windowColor;
  21.         Color fullScreenColor;
  22.         GraphicsDeviceManager graphics;
  23.         SpriteBatch spriteBatch;
  24.  
  25.         public ScreenToggle()
  26.         {
  27.             graphics = new GraphicsDeviceManager(this);
  28.             Content.RootDirectory = "Content";
  29.         }
  30.  
  31.         /// <summary>
  32.         /// Allows the game to perform any initialization it needs to before starting to run.
  33.         /// This is where it can query for any required services and load any non-graphic
  34.         /// related content.  Calling base.Initialize will enumerate through any components
  35.         /// and initialize them as well.
  36.         /// </summary>
  37.         protected override void Initialize()
  38.         {
  39.             // TODO: Add your initialization logic here
  40.             windowColor = new Color(255, 0, 0);
  41.             fullScreenColor = new Color(0, 255, 0);
  42.  
  43.             graphics.PreferredBackBufferWidth = 1920;
  44.             graphics.PreferredBackBufferHeight = 1080;
  45.             graphics.IsFullScreen = true;
  46.             graphics.ApplyChanges();
  47.             base.Initialize();
  48.         }
  49.  
  50.         /// <summary>
  51.         /// LoadContent will be called once per game and is the place to load
  52.         /// all of your content.
  53.         /// </summary>
  54.         protected override void LoadContent()
  55.         {
  56.             // Create a new SpriteBatch, which can be used to draw textures.
  57.             spriteBatch = new SpriteBatch(GraphicsDevice);
  58.  
  59.             // TODO: use this.Content to load your game content here
  60.         }
  61.  
  62.         /// <summary>
  63.         /// UnloadContent will be called once per game and is the place to unload
  64.         /// all content.
  65.         /// </summary>
  66.         protected override void UnloadContent()
  67.         {
  68.             // TODO: Unload any non ContentManager content here
  69.         }
  70.  
  71.         /// <summary>
  72.         /// Allows the game to run logic such as updating the world,
  73.         /// checking for collisions, gathering input, and playing audio.
  74.         /// </summary>
  75.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  76.         protected override void Update(GameTime gameTime)
  77.         {
  78.             // Allows the game to exit
  79.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  80.                 this.Exit();
  81.  
  82.             // TODO: Add your update logic here
  83.             if (Keyboard.GetState().IsKeyDown(Keys.Space))
  84.             {
  85.                 if (graphics.IsFullScreen)
  86.                 {
  87.                     graphics.PreferredBackBufferWidth = 300;
  88.                     graphics.PreferredBackBufferHeight = 300;
  89.                     graphics.IsFullScreen = false;
  90.                     graphics.ApplyChanges();
  91.                 }
  92.             }
  93.             base.Update(gameTime);
  94.         }
  95.  
  96.         /// <summary>
  97.         /// This is called when the game should draw itself.
  98.         /// </summary>
  99.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  100.         protected override void Draw(GameTime gameTime)
  101.         {
  102.             GraphicsDevice.Clear(Color.CornflowerBlue);
  103.  
  104.             // TODO: Add your drawing code here
  105.             if (graphics.IsFullScreen)
  106.                 GraphicsDevice.Clear(fullScreenColor);
  107.             else
  108.                 GraphicsDevice.Clear(windowColor);
  109.             base.Draw(gameTime);
  110.         }
  111.     }
  112. }
RAW Paste Data
Pastebin PRO Autumn Special!
Get 40% OFF on Pastebin PRO accounts!
Top