public MeasureString ( string text, |
||
text | string | The String. |
font | The Font. | |
Результат | Vector2 |
public void Draw(SpriteBatch spriteBatch, GameTime gameTime) { p1Bounds = new Rectangle(new Vector2(0, 0), spriteBatch.MeasureString(scoreBoardPlayer1, Font)); p2Bounds = new Rectangle(new Vector2(GraphicsDevice.BackBuffer.Width - spriteBatch.MeasureString(scoreBoardPlayer2, Font).X, 0), spriteBatch.MeasureString(scoreBoardPlayer2, Font)); spriteBatch.DrawString(scoreBoardPlayer1, Font, p1Bounds, Color); spriteBatch.DrawString(scoreBoardPlayer2, Font, p2Bounds, Color); }
/// <summary> /// Draws the MenuButton. /// </summary> /// <param name="spriteBatch">The spriteBatch.</param> public override void OnDraw(SpriteBatch spriteBatch) { Vector2 dim = spriteBatch.MeasureString(Text, _font); spriteBatch.DrawString(Text, _font, new Vector2(Position.X - (dim.X/2) + (Size.Width/2), Position.Y - (dim.Y/2) + (Size.Height/2)), IsMouseHoverState ? Color.DarkOrange : Color.White); }
/// <summary> /// Draws the Scene. /// </summary> /// <param name="spriteBatch">The spriteBatch.</param> /// <param name="gameTime">The GameTime.</param> public override void Draw(SpriteBatch spriteBatch, GameTime gameTime) { spriteBatch.DrawTexture(_background, _backgroundPosition); Vector2 dim = spriteBatch.MeasureString( string.Format("score: {0}", _finalScore), _font); Vector2 dim2 = spriteBatch.MeasureString("Press {Enter} to continue", _font2); Vector2 dim3 = spriteBatch.MeasureString( string.Format("(Achievement multiplier {0}x)", _achievmentMultiplier), _font3); spriteBatch.DrawString( string.Format("score: {0}", _finalScore), _font, new Vector2(400 - dim.X/2, 300), Color.White); spriteBatch.DrawString(string.Format("(Achievement multiplier {0}x)", _achievmentMultiplier), _font3, new Vector2(400 - dim3.X/2, 350), Color.White); spriteBatch.DrawString("Press {Enter} to continue", _font2, new Vector2(400 - dim2.X/2, 420), Color.White); _blackBlend.Draw(spriteBatch, gameTime); }
public override void OnDraw(SpriteBatch spriteBatch) { if (this.IsMouseHoverState) { this.Pen.Color = Color.Yellow; } else { this.Pen.Color = Color.White; } float x = (float)(this.Position.X + (double)(this.Size.Width / 2) - spriteBatch.MeasureString(this.Text, this.Font).X / 2.0); float y = (float)(this.Position.Y + (double)(this.Size.Height / 2) - spriteBatch.MeasureString(this.Text, this.Font).Y / 2.0); Vector2 center = new Vector2(x, y); spriteBatch.DrawRectangle(this.Pen, Sharpex2D.Common.Extensions.UIBoundsExtension.ToRectangle(this.Bounds)); spriteBatch.DrawString(this.Text, this.Font, center, Color.White); }
public override void OnDraw(SpriteBatch spriteBatch) { //if (AnimationComplete) // return; if (this.IsMouseHoverState) { this.Pen.Color = Color.FromArgb((int)currentAlpha, 255, 255, 0); } else { this.Pen.Color = Color.FromArgb((int)currentAlpha, 255, 255, 255); } float x = (float)(this.Position.X + (double)(this.Size.Width / 2) - spriteBatch.MeasureString(this.Text, this.Font).X / 2.0); float y = (float)(this.Position.Y + (double)(this.Size.Height / 2) - spriteBatch.MeasureString(this.Text, this.Font).Y / 2.0); Vector2 center = new Vector2(x, y); spriteBatch.DrawRectangle(this.Pen, Sharpex2D.Common.Extensions.UIBoundsExtension.ToRectangle(this.Bounds)); spriteBatch.DrawString(this.Text, this.Font, center, Color.FromArgb((int)currentAlpha, 255, 255, 255)); }
/// <summary> /// Zeichnen der Elemente /// </summary> /// <param name="spriteBatch"></param> /// <param name="gameTime"></param> public override void Draw(SpriteBatch spriteBatch, GameTime gameTime) { switch (SceneMode) { case SceneMode.FirstStart: text = "Bereit?"; gameScene.Draw(spriteBatch, gameTime); break; case SceneMode.Paused: text = "Pausiert"; break; case SceneMode.WonLost: break; case SceneMode.Scored: text = "Bereit?"; gameScene.Draw(spriteBatch, gameTime); break; default: break; } font = new Font("Arial", 50, TypefaceStyle.Bold); position = new Vector2() { X = (graphicsDevice.BackBuffer.Width - spriteBatch.MeasureString(text, font).X) / 2, Y = 100 }; color = Color.White; spriteBatch.DrawString(text, font, position, color); }