public override void Draw(MenuScreen screen, bool isSelected, GameTime gameTime, bool fade) { Texture2D bttnTexture; Texture2D bttnpressedTexture; //Check to make sure we haven't defined a texture in the constructor if (mainTexture == null) { bttnTexture = screen.ScreenManager.ButtonTexture; bttnpressedTexture = screen.ScreenManager.ButtonPressedTexture; } else { bttnTexture = this.mainTexture; bttnpressedTexture = this.pressedTexture; } ScreenManager screenManager = screen.ScreenManager; SpriteBatch spriteBatch = screenManager.SpriteBatch; SpriteFont font = screenManager.Font; #if WINDOWS_PHONE isSelected = false; #endif // Draw the selected entry in yellow, otherwise check to see if the font color was set, if it wasn't use Black. Color color = isSelected ? Color.Yellow : fontColor; // Pulsate the size of the selected menu entry. double time = gameTime.TotalGameTime.TotalSeconds; float pulsate = (float)Math.Sin(time * 6) + 1; float scale = 1 + pulsate * 0.05f * selectionFade; // Modify the alpha to fade text out during transitions. if (fade) color *= screen.TransitionAlpha; if (!buttonPressed) currentTexture = bttnTexture; else currentTexture = bttnpressedTexture; if (textFont != null) font = textFont; spriteBatch.Draw(currentTexture, Position, (fade) ? Color.White * screen.TransitionAlpha : Color.White); Vector2 origin = new Vector2(0, font.LineSpacing / 2); Vector2 fontPosition = new Vector2(position.X + (GetWidth(screen) / 2) - (font.MeasureString(text).X / 2), position.Y + (GetHeight(screen) / 2)); spriteBatch.DrawString((textFont == null) ? font : textFont, text, fontPosition, color, 0, origin, scale, SpriteEffects.None, 0); }
public CreditsScreen(MenuScreen backScreen) : base("SodaPop Games") { this.menuTitleColor = Color.White; this.fadeOptions = true; this.TitleYPosition = 240; this.backScreen = backScreen; }
/// <summary> /// Updates the menu entry. /// </summary> public virtual void Update(MenuScreen screen, bool isSelected, GameTime gameTime) { // there is no such thing as a selected item on Windows Phone, so we always // force isSelected to be false #if WINDOWS_PHONE isSelected = false; #endif // When the menu selection changes, entries gradually fade between // their selected and deselected appearance, rather than instantly // popping to the new state. float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4; if (isSelected) selectionFade = Math.Min(selectionFade + fadeSpeed, 1); else selectionFade = Math.Max(selectionFade - fadeSpeed, 0); }
/// <summary> /// Queries how wide the entry is, used for centering on the screen. /// </summary> public virtual int GetWidth(MenuScreen screen) { return (Font == null) ? (int)screen.ScreenManager.Font.MeasureString(Text).X : (int)Font.MeasureString(Text).X; }
/// <summary> /// Queries how much space this menu entry requires. /// </summary> public virtual int GetHeight(MenuScreen screen) { return (Font == null) ? (int)screen.ScreenManager.Font.MeasureString(Text).Y : (int)Font.MeasureString(Text).Y; }
/// <summary> /// Draws the menu entry. This can be overridden to customize the appearance. /// </summary> public virtual void Draw(MenuScreen screen, bool isSelected, GameTime gameTime, bool fade) { // there is no such thing as a selected item on Windows Phone, so we always // force isSelected to be false #if WINDOWS_PHONE isSelected = false; #endif // Draw the selected entry in yellow, otherwise check to see if the font color was set, if it wasn't use Black. Color color = isSelected ? Color.Yellow : fontColor; // Pulsate the size of the selected menu entry. double time = gameTime.TotalGameTime.TotalSeconds; float pulsate = (float)Math.Sin(time * 6) + 1; float scale = 1 + pulsate * 0.05f * selectionFade; // Modify the alpha to fade text out during transitions. if (fade) color *= screen.TransitionAlpha; // Draw text, centered on the middle of each line. ScreenManager screenManager = screen.ScreenManager; SpriteBatch spriteBatch = screenManager.SpriteBatch; Vector2 origin = new Vector2(0, (Font == null) ? screenManager.Font.LineSpacing / 2 : Font.LineSpacing / 2); if (OutLine) { spriteBatch.DrawString((Font == null) ? screenManager.Font : Font, text, new Vector2(position.X + 1, position.Y + 1), Color.Black, 0, origin, scale, SpriteEffects.None, 0); } spriteBatch.DrawString((Font == null) ? screenManager.Font : Font, text, position, color, 0, origin, scale, SpriteEffects.None, 0); }
public override int GetWidth(MenuScreen screen) { if (this.mainTexture == null) return screen.ScreenManager.ButtonTexture.Width; else return mainTexture.Width; }
public override int GetHeight(MenuScreen screen) { if (this.mainTexture == null) return screen.ScreenManager.ButtonTexture.Height; else return mainTexture.Height; }