GumBatch
Introduction
GumBatch is an object which supports immediate mode rendering, similar to MonoGame's SpriteBatch. GumBatch can support rendering text with DrawString as well as any IRenderableIpso.
For information on getting your project set up to use GumBatch, see the Setup for GumBatch page.
Rendering Strings
GumBatch can be used to render strings directly. This requires a BitmapFont.
The following code renders a string at X = 100, Y=200:
gumBatch.Begin();
gumBatch.DrawString(
font,
"I am at X=100, Y=200",
new Vector2(100, 200),
Color.White);
gumBatch.End();
Multiple strings can be rendered between Begin and End calls:

DrawString can accept newlines and color the text:

Rendering TextRuntimes
If your text rendering requires more advanced positioning, wrapping, rotation, sizing, and so on, you can use TextRuntime instances.
TextRuntimes can be used in both GumBatch as well as they can be added to the SystemManagers if you use SystemManagers.Draw (retained mode).
The following code shows how to create a TextRuntime instance and render it using GumBatch:

Rendering Parent/Child Hierarchy
GumBatch.Draw renders any argument renderable object. If the object has children, then the Draw call performs a hierarchical draw, respecting the parent/child relationship to control draw order.
For example, the following code creates a parent ColoredRectangleRuntime and a child TextRuntime:
Since the Draw call is only called on the Parent, then only the Parent reference is kept at class scope:

RenderTargets
GumBatch can be used to render Gum objects on RenderTarget2Ds, just like regular SpriteBatch calls.
The following code shows how to render on a RenderTarget:
Note that if you are rendering multiple objects on a render target, the BlendState must be set as to add the transparency. Using the default BlendState may result in alpha being "removed" from the render target when new instances are drawn.
The following shows how to create a BlendState for objects which have partial transparency and are to be drawn on RenderTargets:
Last updated
Was this helpful?

