如何对齐文本通过SpriteBatch.DrawString画? [英] How to align text drawn by SpriteBatch.DrawString?
问题描述
有没有一种简单的方法来对齐文本的权利和中心(而不是默认的左)?
Is there an easy way to align text to the right and center (instead of default left)?
推荐答案
第一步是通过测量字符串<一href="http://msdn.microsoft.com/en-us/library/bb464128%28v=xnagamestudio.30%29.aspx"><$c$c>SpriteFont.MeasureString()$c$c>.
The first step is to measure the string using SpriteFont.MeasureString()
.
然后,例如,如果你想将它画到一定点的左边,而不是在右边的是默认的,那么你就需要从文本绘制原点减去测量的X宽。如果你希望它为中心,那么你可以用一半的测量等。
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.
这篇关于如何对齐文本通过SpriteBatch.DrawString画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!