How to align text drawn by SpriteBatch.DrawString?

前端 未结 3 1173
广开言路
广开言路 2021-02-05 14:16

Is there an easy way to align text to the right and center (instead of default left)?

3条回答
  •  别那么骄傲
    2021-02-05 14:53

    SpriteFont mFont;
    SpriteBatch mSprite;
    
    mSprite.Begin();
    mSprite.DrawString(mFont, "YourText", new Vector2(graphicsDevice.Viewport.Width / 2 - mFont.MeasureString("YourText").Length() / 2, 0), Color.White, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 0f);
    mSprite.End();
    

提交回复
热议问题