本文整理匯總了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;
}