本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.SpriteFont.GetHeight方法的典型用法代码示例。如果您正苦于以下问题:C# SpriteFont.GetHeight方法的具体用法?C# SpriteFont.GetHeight怎么用?C# SpriteFont.GetHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.SpriteFont
的用法示例。
在下文中一共展示了SpriteFont.GetHeight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromText
public static Texture2D FromText(string text, SpriteFont font, Color color, Size size, bool multiLine, int lineStart, GraphicsDevice device)
{
string[] drawAbleText = multiLine ? text.Split(new string[1] { "\n" }, StringSplitOptions.None) : new string[1] { text };
RenderTarget2D target = new RenderTarget2D(device, size.Width, size.Height);
SpriteBatch sb = new SpriteBatch(device);
device.SetRenderTarget(target);
device.Clear(Color.Transparent);
sb.Begin();
for (int i = lineStart; i < drawAbleText.Length; i++)
{
float y = 1 + (i - lineStart) * font.GetHeight();
sb.DrawString(font, drawAbleText[i], new Vector2(1, y), color, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
}
sb.End();
device.SetRenderTarget(null);
Texture2D texture = new Texture2D(device, size.Width, size.Height);
Color[] colorData = target.GetColorData();
texture.SetData(colorData);
target.Dispose();
sb.Dispose();
return texture;
}