How to align text drawn by SpriteBatch.DrawString?

前端 未结 3 1161
广开言路
广开言路 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:49

    The first step is to measure the string using SpriteFont.MeasureString().

    Then, for example if you want to draw it to the left of a certain point, instead of to the right as is the default, then you need to subtract the X width of the measurement from the text drawing origin. If you want it to be centered, then you can use half the measurement, etc.

提交回复
热议问题