public override void Draw(GameTime gameTime) { // Wait for the loader to complete before attempting to get backgrounds, etc. var babyPackpageProvider = this.Game.Services.GetService <IBabyPackageProvider>(); this.Game.GraphicsDevice.Clear(babyPackpageProvider.GetBackgroundColour()); // Show the background image. var background = babyPackpageProvider.GetBackground(); if (background != null) { // Resize to fit to the screen. var resized = Vector2Helper.ResizeKeepingAspectRatio(this.Game.GraphicsDevice.Viewport.Bounds, background.Bounds); Rectangle r; if (resized.X == this.Game.GraphicsDevice.Viewport.Bounds.Width) { r = new Rectangle(0, (int)((this.Game.GraphicsDevice.Viewport.Bounds.Height - resized.Y) / 2), (int)resized.X, (int)resized.Y); } else { r = new Rectangle((int)((this.Game.GraphicsDevice.Viewport.Bounds.Width - resized.X) / 2), 0, (int)resized.X, (int)resized.Y); } this._SpriteBatch.Begin(); this._SpriteBatch.Draw(background, r, Color.White); this._SpriteBatch.End(); } }
protected override void Draw(GameTime gameTime) { this.GraphicsDevice.Clear(Color.Black); this._SpriteBatch.Begin(); var drawingPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X + 20, GraphicsDevice.Viewport.TitleSafeArea.Y + 20); if (this._State == ScreenState.GeneralMessageCountdown) { // Draw the message. this._SpriteBatch.DrawString(this._LargeFont, this._Message, drawingPosition, Color.White); // And the bug! var resized = Vector2Helper.ResizeKeepingAspectRatio(Vector2Helper.GetProportionalSize(0.5f, this.GraphicsDevice.Viewport), this._Bug.Bounds); var location = new Vector2((float)this.GraphicsDevice.Viewport.Bounds.Center.X, (float)(this.GraphicsDevice.Viewport.Bounds.Bottom - (resized.Y + 10))); var rect = new Rectangle((int)location.X, (int)location.Y, (int)resized.X, (int)resized.Y); var centre = new Vector2((float)this._Bug.Width, (float)this._Bug.Height) / 2; this._SpriteBatch.Draw(this._Bug, rect, null, Color.White, 0f, centre, SpriteEffects.None, 0); } else if (this._State == ScreenState.TechnicalDisplay) { // Draw the exception message. this._SpriteBatch.DrawString(this._LargeFont, this._Message, drawingPosition, Color.White); this._SpriteBatch.DrawString(this._SmallFont, this._TheExceptionDump, drawingPosition + new Vector2(0, 30), Color.White); } else if (this._State == ScreenState.PublishException) { // Draw the publishing message. this._SpriteBatch.DrawString(this._LargeFont, this._Message, drawingPosition, Color.White); // And the bug! var resized = Vector2Helper.ResizeKeepingAspectRatio(Vector2Helper.GetProportionalSize(0.5f, this.GraphicsDevice.Viewport), this._Bug.Bounds); var location = new Vector2((float)this.GraphicsDevice.Viewport.Bounds.Center.X, (float)(this.GraphicsDevice.Viewport.Bounds.Bottom - (resized.Y + 10))); var rect = new Rectangle((int)location.X, (int)location.Y, (int)resized.X, (int)resized.Y); var centre = new Vector2((float)this._Bug.Width, (float)this._Bug.Height) / 2; this._SpriteBatch.Draw(this._Bug, rect, null, Color.White, 0f, centre, SpriteEffects.None, 0); } this._SpriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { if (this.FadeInTime > TimeSpan.Zero && this.SpinTime > TimeSpan.Zero) { throw new InvalidOperationException("Unable to Fade In and Spin In at the same time. Set FadeInTime or SpinTime to TimeSpan.Zero."); } if (this.ActualSize == Vector2.Zero) { this.ActualSize = Vector2Helper.ResizeKeepingAspectRatio(this.Size, this.Texture.Bounds); } if (this.Location == Vector2.Zero) { // Choose a location for the shape to appear. this.Location = new Vector2( (float)this.Game.RandomGenerator.Next(this.Game.GraphicsDevice.Viewport.X + (int)(this.ActualSize.X * 0.2f), this.Game.GraphicsDevice.Viewport.Width - (int)(this.ActualSize.X * 0.2f)) , (float)this.Game.RandomGenerator.Next(this.Game.GraphicsDevice.Viewport.Y + (int)(this.ActualSize.Y * 0.2f), this.Game.GraphicsDevice.Viewport.Height - (int)(this.ActualSize.Y * 0.2f)) ); } // Update the state machine for this lifespan of this object. while (this.RemainingTimeInCurrentState <= TimeSpan.Zero && this.State != DrawingState.PostShow) { switch (this.State) { case DrawingState.PreShow: if (this.FadeInTime > TimeSpan.Zero) { this.State = DrawingState.FadeIn; this.RemainingTimeInCurrentState = this.FadeInTime; } else if (this.SpinTime > TimeSpan.Zero) { this.State = DrawingState.SpinIn; this.RemainingTimeInCurrentState = this.SpinTime; } else { this.State = DrawingState.Solid; this.RemainingTimeInCurrentState = this.SolidTime; } break; case DrawingState.FadeIn: this.State = DrawingState.Solid; this.RemainingTimeInCurrentState = this.SolidTime; break; case DrawingState.SpinIn: this.State = DrawingState.Solid; this.RemainingTimeInCurrentState = this.SolidTime; break; case DrawingState.Solid: this.State = DrawingState.FadeOut; this.RemainingTimeInCurrentState = this.FadeOutTime; break; case DrawingState.FadeOut: this.State = DrawingState.PostShow; break; case DrawingState.PostShow: break; default: throw new ApplicationException("Forgot a DrawingState."); } } this.RemainingTimeInCurrentState = this.RemainingTimeInCurrentState.Subtract(gameTime.ElapsedGameTime); base.Update(gameTime); }