All pastes #498682 Raw Edit

Mine

public text v1 · immutable
·published 2007-05-20 16:31 UTC
rendered paste body
public class OnScreenText : DrawableGameComponent
{
    IGraphicsDeviceService graphicsService;

    Font segoeUi10;
    SpriteBatch spriteBatch;

    public OnScreenText(Game game) : base(game) { }

    public override void Initialize()
    {
        graphicsService = Game.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;

        base.Initialize();
    }

    protected override void LoadGraphicsContent(bool loadAllContent)
    {
        if (loadAllContent)
        {
            ContentManager content = (Game.Services.GetService(typeof(IContentManagerService)) as IContentManagerService).ContentManager;
            segoeUi10 = content.Load<Font>("Content/Fonts/SegoeUi10");

            if(spriteBatch != null) spriteBatch.Dispose(); // Needed?
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }

        base.LoadGraphicsContent(loadAllContent);
    }

    public override void Draw(GameTime gameTime)
    {
        spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
        segoeUi10.Draw("Segoe UI 10", new Vector2(5, 65), 1, Color.White, spriteBatch);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}