# PendulumGame.PendulumVideoScreen Class Reference

Plays a video file. More...

Inheritance diagram for PendulumGame.PendulumVideoScreen:

List of all members.

## Public Member Functions
| PendulumVideoScreen ()
| Constructor.
override void | LoadContent ()
| Loads graphics content for this screen. The background texture is quite big, so we use our own local ContentManager to load it. This allows us to unload before going from the menus into the game itself, wheras if we used the shared ContentManager provided by the Game class, the content would remain loaded forever.
override void | UnloadContent ()
| Unloads graphics content for this screen.
override void | HandleInput (InputState input)
| Lets the game respond to player input. Unlike the Update method, this will only be called when the gameplay screen is active.
override void | Update (GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
| Updates the background screen. Unlike most screens, this should not transition off even if it has been covered by another screen: it is supposed to be covered, after all! This overload forces the coveredByOtherScreen parameter to false in order to stop the base Update method wanting to transition off.
override void | Draw (GameTime gameTime)
| Draws the background screen.

## Detailed Description

Plays a video file.

Definition at line 22 of file PendulumVideoScreen.cs.

## Constructor & Destructor Documentation

PendulumGame.PendulumVideoScreen.PendulumVideoScreen | ( |  | ) |

Constructor.

Definition at line 58 of file PendulumVideoScreen.cs.

    00059         {
    00060             TransitionOnTime = TimeSpan.FromSeconds(0.5);
    00061             TransitionOffTime = TimeSpan.FromSeconds(0.5);
    00062         }

## Member Function Documentation

override void PendulumGame.PendulumVideoScreen.Draw | ( | GameTime | gameTime | ) | `[virtual]`

Draws the background screen.

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Definition at line 189 of file PendulumVideoScreen.cs.

    00190         {
    00191             SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
    00192             Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
    00193             Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
    00194             byte fade = TransitionAlpha;
    00195
    00196             // Render the video in it's orginal resolution
    00197             // to the screen using SpriteBatch
    00198             if (ScreenManager.VideoPlayer.State == MediaState.Playing)
    00199             {
    00200                 spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
    00201                 effect.Begin();
    00202                 float threshold = 0.3f;
    00203                 effect.Parameters["referenceColor"].SetValue(this.referenceColor.ToVector3());
    00204                 effect.Parameters["threshold"].SetValue(threshold);
    00205                 foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    00206                 {
    00207                     pass.Begin();
    00208                     spriteBatch.Draw(
    00209                         ScreenManager.VideoPlayer.GetTexture(),
    00210                         new Rectangle(
    00211                             (viewport.Width - videoFile.Width) / 2,
    00212                             (viewport.Height - videoFile.Height) / 2,
    00213                             videoFile.Width,
    00214                             videoFile.Height),
    00215                         new Color(fade, fade, fade));
    00216                     pass.End();
    00217                 }
    00218                 effect.End();
    00219                 spriteBatch.End();
    00220             }
    00221         }

override void PendulumGame.PendulumVideoScreen.HandleInput | ( | InputState | input | ) | `[virtual]`

Lets the game respond to player input. Unlike the Update method, this will only be called when the gameplay screen is active.

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Definition at line 121 of file PendulumVideoScreen.cs.

    00122         {
    00123             if (input == null)
    00124             {
    00125                 throw new ArgumentNullException("input");
    00126             }
    00127
    00128             if (input.IsInputCancel(null) || input.IsDisconnected(null))
    00129             {
    00130                 ScreenManager.AddScreen(new PendulumPauseMenuScreen(), null);
    00131             }
    00132             else
    00133             {
    00134                 PlayerIndex playerIndex;
    00135
    00136                 // Back to main menu
    00137                 if (input.IsMenuCancel(null, out playerIndex) ||
    00138                     input.IsMenuSelect(null, out playerIndex))
    00139                 {
    00140                     PendulumLoadingScreen.Load(
    00141                         ScreenManager, false, null,
    00142                         new PendulumBackgroundScreen(),
    00143                         new PendulumMainMenuScreen());
    00144                 }
    00145             }
    00146         }

override void PendulumGame.PendulumVideoScreen.LoadContent | ( |  | ) | `[virtual]`

Loads graphics content for this screen. The background texture is quite big, so we use our own local ContentManager to load it. This allows us to unload before going from the menus into the game itself, wheras if we used the shared ContentManager provided by the Game class, the content would remain loaded forever.

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Definition at line 71 of file PendulumVideoScreen.cs.

    00072         {
    00073             if (content == null)
    00074             {
    00075                 content = new ContentManager(ScreenManager.Game.Services, "Content");
    00076             }
    00077
    00078             // Pick random video
    00079             int videoNumber = PendulumGame.State.PhysicalRandomNumberGenerator.Next(0, 12);
    00080
    00081             videoFile = content.Load<Video>(@"Videos\Pendulum" + videoNumber);
    00082             effect = content.Load<Effect>(@"Effects\ColorChromaKey");
    00083
    00084             // Determine chromakey reference color by averaging
    00085             // the color over the reference image
    00086             Texture2D backgroundReference =
    00087                 content.Load<Texture2D>(@"Textures\PendulumBackgroundReference");
    00088             Color[] colors = TextureHelpers.TextureToColors(backgroundReference);
    00089             ulong rSum = 0;
    00090             ulong gSum = 0;
    00091             ulong bSum = 0;
    00092             ulong num = (ulong)colors.Length;
    00093             foreach (Color color in colors)
    00094             {
    00095                 rSum += (ulong)color.R;
    00096                 gSum += (ulong)color.G;
    00097                 bSum += (ulong)color.B;
    00098             }
    00099
    00100             this.referenceColor = new Color(
    00101                 (byte)(rSum / num),
    00102                 (byte)(gSum / num),
    00103                 (byte)(bSum / num));
    00104         }

override void PendulumGame.PendulumVideoScreen.UnloadContent | ( |  | ) | `[virtual]`

Unloads graphics content for this screen.

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Definition at line 109 of file PendulumVideoScreen.cs.

    00110         {
    00111             content.Unload();
    00112         }

override void PendulumGame.PendulumVideoScreen.Update | ( | GameTime | gameTime,
|  | bool | otherScreenHasFocus,
|  | bool | coveredByOtherScreen |
| ) |  |  | `[virtual]`

Updates the background screen. Unlike most screens, this should not transition off even if it has been covered by another screen: it is supposed to be covered, after all! This overload forces the coveredByOtherScreen parameter to false in order to stop the base Update method wanting to transition off.

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Definition at line 157 of file PendulumVideoScreen.cs.

    00159         {
    00160             if (!videoStarted)
    00161             {
    00162                 ScreenManager.VideoPlayer.Play(videoFile);
    00163                 videoStarted = true;
    00164             }
    00165             else
    00166             {
    00167                 if (ScreenManager.VideoPlayer.State == MediaState.Stopped)
    00168                 {
    00169                     // Return to main menu
    00170                     PendulumLoadingScreen.Load(ScreenManager, false, null,
    00171                         new PendulumBackgroundScreen(),
    00172                         new PendulumMainMenuScreen());
    00173                 }
    00174             }
    00175
    00176             // If the game is transitioning on or off, fade it out to black.
    00177             if (TransitionPosition > 0)
    00178             {
    00179                 ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
    00180             }
    00181
    00182             base.Update(gameTime, otherScreenHasFocus, false);
    00183         }

The documentation for this class was generated from the following file:

- C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/PendulumGame/Screens/PendulumVideoScreen.cs