/// <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); } }
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> /// 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); } } } }
/// <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); } } }