// In the LoadContent method Texture2D labelTexture = new Texture2D(GraphicsDevice, 300, 50); SpriteFont font = Content.Load("MyFont"); // In the Update method string labelText = "Score: " + score.ToString(); font.DrawInto(labelTexture, labelText, new Vector2(10, 10), Color.Black); // In the Draw method spriteBatch.Draw(labelTexture, new Vector2(0, 0), Color.White);
// In the LoadContent method Texture2D objectTexture = Content.LoadIn this example, we first load in a texture for an object and a SpriteFont. In the Draw method, we draw the object texture to the screen. We then call DrawInto on the SpriteFont and pass in the objectTexture, the label text, a position vector, and a color. This will add the text to the texture and then we draw the updated texture on the screen. Package/library: Microsoft.Xna.Framework.Graphics.("MyObject"); SpriteFont font = Content.Load ("MyFont"); // In the Draw method spriteBatch.Draw(objectTexture, new Vector2(0, 0), Color.White); string objectLabel = "This is my object"; font.DrawInto(objectTexture, objectLabel, new Vector2(10, 10), Color.Black);