如何对齐文本通过SpriteBatch.DrawString画? [英] How to align text drawn by SpriteBatch.DrawString?

查看:147
本文介绍了如何对齐文本通过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().

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆