/// <summary> /// Draws some text from the given font /// </summary> /// <param name="spriteBatch">The sprite batch to use</param> /// <param name="fontStyle">Which font to use</param> /// <param name="x">X position in screen pixel space</param> /// <param name="y">Y position in screen pixel space</param> /// <param name="digits">The characters to draw</param> /// <param name="color">The color to draw it in</param> public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle, int x, int y, string digits, Color color) { float xPosition = x; FontInfo thisFont = fontInfo[(int)fontStyle]; for (int i = 0; i < digits.Length; i++) { //Don't draw anything if its a space character if (digits[i] != ' ') { //Look up the character position int character = thisFont.Characters.IndexOf(digits[i]); //Draw the correct character at the correct position spriteBatch.Draw(fontTextures[(int)fontStyle], new Vector2(xPosition, (float)y), new Rectangle(character * thisFont.CharacterSpacing + thisFont.StartOffset, 0, thisFont.CharacterWidth, thisFont.CharacterHeight), color); } //Move the position of the next character. //If the character is a comma or colon then use a 'fudge factor' to make //the font look a little proportional xPosition += ((digits[i] == ',' || digits[i] == ':') ? thisFont.CharacterWidth / 2 : thisFont.CharacterWidth); } }
/// <summary> /// Tidies up the scene. /// </summary> public virtual void Shutdown() { ShutdownMusic(); if (batch != null) { batch.Dispose(); batch = null; } }
/// <summary> /// Load your graphics content. /// </summary> protected override void LoadContent() { //Re-Create the Sprite Batch! IGraphicsDeviceService graphicsService = Game.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService; batch = new RelativeSpriteBatch(graphicsService.GraphicsDevice); //Load content for any sub components if (!String.IsNullOrEmpty(backgroundImage)) { backgroundTexture = MarbletsGame.Content.Load <Texture2D>(backgroundImage); } }
/// <summary> /// Draws the game board and all child objects /// </summary> /// <param name="spriteBatch">a sprite batch to use to draw any sprites</param> public void Draw(RelativeSpriteBatch spriteBatch) { if (spriteBatch == null) { return; } foreach (Marble marble in Marbles) { if (marble != null) { marble.Draw(spriteBatch); } } if (!GameOver) { //Draw the cursor spriteBatch.Draw(marbleCursorTexture, BoardToScreen(cursorX, cursorY), Color.White); } if (!GameOver) { if (totalSelected > 0) { Vector2 position = BoardToScreen(cursorX, cursorY) + scoreOffset; Color color = Color.White; if (AnimationState == Animation.Breaking) { //Slide the score up and fade it position -= new Vector2(0, scoreFadeFactor * scoreFadeDistance); color = new Color(255, 255, 255, (byte)(255 * (1f - scoreFadeFactor))); } Font.Draw(spriteBatch, FontStyle.Large, position, Score(totalSelected), color); } } }
private void Draw2DMarble(RelativeSpriteBatch spriteBatch) { //Draw the 2d marble if (Animation == Animation.Breaking || Animation == Animation.Gone) { //Draw the correct frame. spriteBatch.Draw(breakTexture, Position, new Rectangle(frame * Width, 0, Width, Height), Color); } else { spriteBatch.Draw(marble, Position, Color); //Highlight selected marbles if (Selected) { if (pulseFactor < 0.0) { //Make a new color with the correct transparency. Color fade = new Color(255, 255, 255, (byte)(-pulseFactor * 255.0)); //pulse the single ring spriteBatch.Draw(glowRing1Texture, Position, fade); } else { //pulse the double ring //Make a new color with the correct transparency. Color fade = new Color(255, 255, 255, (byte)(pulseFactor * 255.0)); spriteBatch.Draw(glowRing2Texture, Position, fade); } } } }
/// <summary> /// Load your graphics content. /// </summary> protected override void LoadContent() { //Re-Create the Sprite Batch! IGraphicsDeviceService graphicsService = Game.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService; batch = new RelativeSpriteBatch(graphicsService.GraphicsDevice); //Load content for any sub components if (!String.IsNullOrEmpty(backgroundImage)) { backgroundTexture = MarbletsGame.Content.Load<Texture2D>(backgroundImage); } }
/// <summary> /// Draws some text from the given font /// </summary> /// <param name="spriteBatch">The sprite batch to use</param> /// <param name="fontStyle">Which font to use</param> /// <param name="position">A vector x,y position</param> /// <param name="number">A number to draw</param> /// <param name="color">The color of the text</param> public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle, Vector2 position, int number, Color color) { Draw(spriteBatch, fontStyle, (int)position.X, (int)position.Y, number.ToString(), color); }
/// <summary> /// Draws some text from the given font /// </summary> /// <param name="spriteBatch">The sprite batch to use</param> /// <param name="fontStyle">Which font to use</param> /// <param name="x">X position in screen pixel space</param> /// <param name="y">Y position in screen pixel space</param> /// <param name="digits">The characters to draw</param> public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle, int x, int y, string digits) { //No color - use 'white' i.e. use whatever is in the file Draw(spriteBatch, fontStyle, x, y, digits, Color.White); }
/// <summary> /// Draws some text from the given font /// </summary> /// <param name="spriteBatch">The sprite batch to use</param> /// <param name="fontStyle">Which font to use</param> /// <param name="x">X position in screen pixel space</param> /// <param name="y">Y position in screen pixel space</param> /// <param name="number">The number to draw</param> public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle, int x, int y, int number) { //No color - use 'white' i.e. use whatever is in the file Draw(spriteBatch, fontStyle, x, y, number.ToString(), Color.White); }
/// <summary> /// Draws the specified marble /// </summary> /// <param name="spriteBatch">The sprite batch to use</param> public void Draw(RelativeSpriteBatch spriteBatch) { Draw2DMarble(spriteBatch); }
/// <summary> /// Draws the game board and all child objects /// </summary> /// <param name="spriteBatch">a sprite batch to use to draw any sprites</param> public void Draw(RelativeSpriteBatch spriteBatch) { if (spriteBatch == null) return; foreach (Marble marble in Marbles) { if (marble != null) { marble.Draw(spriteBatch); } } if (!GameOver) { //Draw the cursor spriteBatch.Draw(marbleCursorTexture, BoardToScreen(cursorX, cursorY), Color.White); } if (!GameOver) { if (totalSelected > 0) { Vector2 position = BoardToScreen(cursorX, cursorY) + scoreOffset; Color color = Color.White; if (AnimationState == Animation.Breaking) { //Slide the score up and fade it position -= new Vector2(0, scoreFadeFactor * scoreFadeDistance); color = new Color(255, 255, 255, (byte)(255 * (1f - scoreFadeFactor))); } Font.Draw(spriteBatch, FontStyle.Large, position, Score(totalSelected), color); } } }
private void Draw2DMarble(RelativeSpriteBatch spriteBatch) { //Draw the 2d marble if(Animation == Animation.Breaking || Animation == Animation.Gone) { //Draw the correct frame. spriteBatch.Draw(breakTexture, Position, new Rectangle(frame * Width, 0, Width, Height), Color); } else { spriteBatch.Draw(marble, Position, Color); //Highlight selected marbles if(Selected) { if(pulseFactor < 0.0) { //Make a new color with the correct transparency. Color fade = Color.White * -pulseFactor; //pulse the single ring spriteBatch.Draw(glowRing1Texture, Position, fade); } else { //pulse the double ring //Make a new color with the correct transparency. Color fade = Color.White * pulseFactor; spriteBatch.Draw(glowRing2Texture, Position, fade); } } } }