Advertisement
SuperLemrick

Looping Colors

Mar 4th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.44 KB | None | 0 0
  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 Looping_Colors
  13. {
  14.     /// <summary>
  15.     /// This is the main type for your game
  16.     /// </summary>
  17.     public class LoopingColor : Microsoft.Xna.Framework.Game
  18.     {
  19.         GraphicsDeviceManager graphics;
  20.         SpriteBatch spriteBatch;
  21.         private Color[] backgroundColors;
  22.         int currentColor;
  23.  
  24.         public LoopingColor()
  25.         {
  26.             graphics = new GraphicsDeviceManager(this);
  27.             Content.RootDirectory = "Content";
  28.         }
  29.  
  30.         /// <summary>
  31.         /// Allows the game to perform any initialization it needs to before starting to run.
  32.         /// This is where it can query for any required services and load any non-graphic
  33.         /// related content.  Calling base.Initialize will enumerate through any components
  34.         /// and initialize them as well.
  35.         /// </summary>
  36.         protected override void Initialize()
  37.         {
  38.             // TODO: Add your initialization logic here
  39.             this.TargetElapsedTime = TimeSpan.FromSeconds(2.0f);
  40.             backgroundColors = new Color[5]
  41.                 { Color.Red, Color.Green, Color.Yellow, Color.Blue, Color.Orange };
  42.             currentColor = 0;
  43.             base.Initialize();
  44.         }
  45.  
  46.         /// <summary>
  47.         /// LoadContent will be called once per game and is the place to load
  48.         /// all of your content.
  49.         /// </summary>
  50.         protected override void LoadContent()
  51.         {
  52.             // Create a new SpriteBatch, which can be used to draw textures.
  53.             spriteBatch = new SpriteBatch(GraphicsDevice);
  54.  
  55.             // TODO: use this.Content to load your game content here
  56.            
  57.         }
  58.  
  59.         /// <summary>
  60.         /// UnloadContent will be called once per game and is the place to unload
  61.         /// all content.
  62.         /// </summary>
  63.         protected override void UnloadContent()
  64.         {
  65.             // TODO: Unload any non ContentManager content here
  66.         }
  67.  
  68.         /// <summary>
  69.         /// Allows the game to run logic such as updating the world,
  70.         /// checking for collisions, gathering input, and playing audio.
  71.         /// </summary>
  72.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  73.         protected override void Update(GameTime gameTime)
  74.         {
  75.             // Allows the game to exit
  76.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  77.                 this.Exit();
  78.  
  79.             // TODO: Add your update logic here
  80.             currentColor++;
  81.  
  82.             if (currentColor >= backgroundColors.Length)
  83.             {
  84.                 currentColor = 0;
  85.             }
  86.             base.Update(gameTime);
  87.         }
  88.  
  89.         /// <summary>
  90.         /// This is called when the game should draw itself.
  91.         /// </summary>
  92.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  93.         protected override void Draw(GameTime gameTime)
  94.         {
  95.             GraphicsDevice.Clear(backgroundColors[currentColor]);
  96.  
  97.             // TODO: Add your drawing code here
  98.  
  99.             base.Draw(gameTime);
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement