- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/PendulumGame/Screens/PendulumBackgroundScreen.cs

    00001 #region File Description
    00002 //-----------------------------------------------------------------------------
    00003 // PendulumBackgroundScreen.cs
    00004 //-----------------------------------------------------------------------------
    00005 #endregion
    00006
    00007 namespace PendulumGame
    00008 {
    00009     using System;
    00010     using Microsoft.Xna.Framework;
    00011     using Microsoft.Xna.Framework.Content;
    00012     using Microsoft.Xna.Framework.Graphics;
    00013     using Microsoft.Xna.Framework.Media;
    00014     using Microsoft.Xna.Framework.Input;
    00015
    00016     using NewGamePhysics.StateManager;
    00017     using NewGamePhysics.Utilities;
    00018
    00024     class PendulumBackgroundScreen : GameScreen
    00025     {
    00026         #region Fields
    00027
    00031         ContentManager content;
    00032
    00036         Texture2D backgroundTexture;
    00037
    00041         Texture2D frameTexture;
    00042
    00046         Texture2D videoTexture;
    00047
    00051         Video videoFile;
    00052
    00056         bool videoStarted = false;
    00057
    00058         #endregion
    00059
    00060         #region Initialization
    00061
    00062
    00066         public PendulumBackgroundScreen()
    00067         {
    00068             TransitionOnTime = TimeSpan.FromSeconds(0.5);
    00069             TransitionOffTime = TimeSpan.FromSeconds(0.5);
    00070         }
    00071
    00072
    00080         public override void LoadContent()
    00081         {
    00082             if (content == null)
    00083             {
    00084                 content = new ContentManager(ScreenManager.Game.Services, "Content");
    00085             }
    00086
    00087             backgroundTexture = content.Load<Texture2D>(@"Sprites\background");
    00088             frameTexture = content.Load<Texture2D>(@"Sprites\frame");
    00089             videoFile = content.Load<Video>(@"Videos\DoublePendulumTitle-CBR");
    00090         }
    00091
    00095         public override void UnloadContent()
    00096         {
    00097             ScreenManager.VideoPlayer.Stop();
    00098             content.Unload();
    00099         }
    00100
    00101
    00102         #endregion
    00103
    00104         #region Update and Draw
    00105
    00106
    00114         public override void Update(GameTime gameTime, bool otherScreenHasFocus,
    00115                                                        bool coveredByOtherScreen)
    00116         {
    00117             base.Update(gameTime, otherScreenHasFocus, false);
    00118             if (!videoStarted)
    00119             {
    00120                 ScreenManager.VideoPlayer.Play(videoFile);
    00121                 videoStarted = true;
    00122             }
    00123             else
    00124             {
    00125                 if (ScreenManager.VideoPlayer.State == MediaState.Playing)
    00126                 {
    00127                     videoTexture = ScreenManager.VideoPlayer.GetTexture();
    00128                 }
    00129                 else if (ScreenManager.VideoPlayer.State == MediaState.Stopped)
    00130                 {
    00131                     videoStarted = false;
    00132                 }
    00133             }
    00134         }
    00135
    00139         public override void Draw(GameTime gameTime)
    00140         {
    00141             SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
    00142             Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
    00143             Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
    00144             byte transparency = TransitionAlpha;
    00145             byte intensity = 192;
    00146
    00147             spriteBatch.Begin(SpriteBlendMode.None);
    00148             spriteBatch.Draw(
    00149                 backgroundTexture,
    00150                 fullscreen,
    00151                 Color.White);
    00152             spriteBatch.End();
    00153
    00154             spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
    00155             if (videoTexture != null)
    00156             {
    00157                 spriteBatch.Draw(
    00158                     videoTexture,
    00159                     fullscreen,
    00160                     new Color(intensity, intensity, intensity, transparency));
    00161             }
    00162
    00163             spriteBatch.Draw(
    00164                 frameTexture,
    00165                 fullscreen,
    00166                 Color.White);
    00167             spriteBatch.End();
    00168
    00169             // If the game is transitioning on or off, fade it out to black.
    00170             if (TransitionPosition > 0)
    00171             {
    00172                 ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
    00173             }
    00174         }
    00175
    00176         #endregion
    00177     }
    00178 }