SpriteFont
AdvancedProgrammer SpriteFont class is a convenient way to draw text. It works with the SpriteBatch class.
Note
Custom scene renderer to include it in the composition.
Load a spriteFont
SpriteFont instance using the @’Xenko.Core.Serialization.Assets.ContentManager’. It contains all the options to display a text (bitmaps, kerning, line spacing etc). Code: Load a SpriteFont
var myFont = Content.Load<SpriteFont>("MyFont");
Write text on screen
SpriteBatch. The @’Xenko.Graphics.SpriteBatch.DrawString’ method performs the draw. For more information about the SpriteBatch, see the SpriteBatch page. Code: Write text
// create the SpriteBatchvar spriteBatch = new SpriteBatch(GraphicsDevice);// don't forget the beginspriteBatch.Begin(GraphicsContext);// draw the text "Helloworld!" in red from the center of the screenspriteBatch.DrawString(myFont, "Helloworld!", new Vector2(0.5, 0.5), Color.Red);// don't forget the endspriteBatch.End();
SpriteEffects to the text:
