Setup for GumBatch

Introduction

Gum provides a GumBatch object which works similar to GumBatch. It can be used for immediate mode rendering, which allows for calling Begin, Draw, and End just like SpriteBatch. This is useful if your project requires mixing Gum and MonoGame rendering, or if you are more comfortable using a SpriteBatch-like interface.

This page assumes you have an existing MonoGame project. This can be an empty project or an existing game.

Adding Gum Nuget Packages

  1. Open your MonoGame project in your preferred IDE.

  2. Add the Gum.MonoGame NuGet package

GumBatch Quick Start

To initialize a GumBatch, you must:

  • Declare a GumBatch at class scope

  • Initialize the Gum SystemManagers - this is needed whether you use GumBatch or the full Gum retained mode rendering system

  • Initialize the GumBatch

  • (optional) load a .fnt file

  • Draw with gumBatch in your Draw

The following shows a simple Game1.cs file which renders Gum Text:

public class Game1 : Game
{
    private GraphicsDeviceManager _graphics;
    RenderingLibrary.Graphics.BitmapFont font;
    GumBatch gumBatch;

    public Game1()
    {
        _graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        IsMouseVisible = true;
    }

    protected override void Initialize()
    {
        SystemManagers.Default = new SystemManagers();
        SystemManagers.Default.Initialize(_graphics.GraphicsDevice, fullInstantiation: true);

        gumBatch = new GumBatch();
        font = new RenderingLibrary.Graphics.BitmapFont(
            "Fonts/Font18Caladea.fnt", 
            SystemManagers.Default);

        base.Initialize();
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        gumBatch.Begin();
        
        gumBatch.DrawString(
            font, 
            "This is using Gum Batch", 
            new Vector2(0, 150), 
            Color.White);
            
        gumBatch.End();

        base.Draw(gameTime);
    }
}

This code produces the following image:

Note that this code assumes a font .fnt file (and matching .png) are in the Content/Fonts/ folder. All content is loaded relative to the Content folder, just like normal content in MonoGame. Also note that this content does not use the content pipeline, but must be set to Copy to Output.

For more information on loading FNT files, see the File Loading documentation.

For a more detailed discussion of using GumBatch, see the GumBatch page.

Last updated