/// <summary>Updates the currently displayed background</summary> /// <param name="TimeElapsed">The time elapsed since the previous call to this function</param> /// <param name="GamePaused">Whether the game is currently paused</param> public void UpdateBackground(double TimeElapsed, bool GamePaused) { if (GamePaused) { //Don't update the transition whilst paused TimeElapsed = 0.0; } const float scale = 0.5f; // fog const float fogDistance = 600.0f; if (CurrentFog.Start < CurrentFog.End & CurrentFog.Start < fogDistance) { float ratio = (float)CurrentBackground.BackgroundImageDistance / fogDistance; renderer.OptionFog = true; renderer.Fog.Start = CurrentFog.Start * ratio * scale; renderer.Fog.End = CurrentFog.End * ratio * scale; renderer.Fog.Color = CurrentFog.Color; renderer.SetFogForImmediateMode(); } else { renderer.OptionFog = false; } //Update the currently displayed background CurrentBackground.UpdateBackground(SecondsSinceMidnight, TimeElapsed, false); if (TargetBackground == null || TargetBackground == CurrentBackground) { //No target background, so call the render function renderer.Background.Render(CurrentBackground, scale); return; } //Update the target background if (TargetBackground is StaticBackground) { TargetBackground.Countdown += TimeElapsed; } TargetBackground.UpdateBackground(SecondsSinceMidnight, TimeElapsed, true); switch (TargetBackground.Mode) { //Render, switching on the transition mode case BackgroundTransitionMode.FadeIn: renderer.Background.Render(CurrentBackground, 1.0f, scale); renderer.Background.Render(TargetBackground, TargetBackground.CurrentAlpha, scale); break; case BackgroundTransitionMode.FadeOut: renderer.Background.Render(TargetBackground, 1.0f, scale); renderer.Background.Render(CurrentBackground, TargetBackground.CurrentAlpha, scale); break; } //If our target alpha is greater than or equal to 1.0f, the background is fully displayed if (TargetBackground.CurrentAlpha >= 1.0f) { //Set the current background to the target & reset target to null CurrentBackground = TargetBackground; TargetBackground = null; } }