For the complete documentation index, see llms.txt. This page is also available as Markdown.

BBCode

Introduction

TextRuntime supports using BBCode-like syntax for formatting individual words and letters. Customizations include changing size, font, and even using custom functions.

Using BBCode for TextRuntimes supports all of the functionality outlined in the Text documentation which can be found here: https://docs.flatredball.com/gum/gum-tool/gum-elements/text/text#using-bbcode-for-inline-styling

The following BBCode variables require font generation:

  • IsBold

  • IsItalic

  • Font

  • FontSize

  • OutlineThickness

The Gum tool generates fonts automatically into the FontCache folder. For code-only projects, the recommended approach is to use dynamic font generation via KernSmith, which handles font creation at runtime with no extra setup. Without the Gum tool or KernSmith, you must provide pre-built .fnt files for each font combination your BBCode text uses.

The following variables work without any font setup:

  • Color

  • Red/Green/Blue

  • FontScale

  • Custom (see below)

Code Example: Basic BBCode Styling

The following example shows how to use BBCode tags for inline color and scale changes:

Try on XnaFiddle.NET

BBCode tags can be nested and combined. Tags are written as [TagName=Value]text[/TagName]. The supported tags include Color, Red, Green, Blue, FontScale, Font, FontSize, IsBold, IsItalic, OutlineThickness, and Custom.

Custom Functions

TextRuntime instances can use the Custom tag to define a custom function to be used when rendering a Text. This tag can be used to customize letters in a TextRuntime using custom code, allowing for effects such as wavy, rainbow, or shaking text.

The following variables can be modified on each letter. This list also includes their default values:

  • XOffset = 0

  • YOffset = 0

  • Color = null

  • ScaleX = 1

  • ScaleY = 1

  • RotationDegrees = 0

  • ReplacementCharacter = null

To use the Custom tag, the following must be performed:

  1. A function must be declared which is of one of the following types:

    • Func<int, string, LetterCustomization> - the int value represents the index in the custom block, starting with 0. The string represents the entire string in the block. The returned LetterCustomization instance includes the desired modifications to the letter. Register with Text.Customizations.

    • Func<int, string, LetterCustomization, LetterCustomization> - same as above, but the third parameter is a LetterCustomization containing the letter's current state (color, offset, scale) as set by prior BBCode tags. This allows relative modifications such as darkening the current color. Register with Text.ContextCustomizations.

  2. This function must be registered with the RenderingLibrary.Graphics.Text type using the appropriate dictionary.

  3. A Custom tag must be included in the text string.

Code Example: Shaking Letters With Custom Tag

The following code block shows how to create a TextRuntime with letters shaking horizontally:

TextRuntime displaying shaking the word "cold"

Code Example: On-Command Custom Values

Custom tags can reference functions inside of classes which can provide additional customization, such as one-time changes.

The following code shows how to make text grow and shrink one time whenever gold is added. First, we create a class that includes the logic for growing/shrinking. This class also stores a StartTime variable which is used to determine the text size. Note that this is using a DateTime for simplicity, but you could also game time or other timing methods.

We can register this function and use it on a TextRuntime. The following code creates a button which increases the gold and resets the start time:

Button adding gold and resetting the grow shirnk time.

Code Example: Context-Aware Custom Function

Custom functions can optionally receive the letter's current state as a LetterCustomization parameter. This is useful for making relative modifications — for example, darkening whatever color was set by prior BBCode tags.

The context parameter includes the current Color, XOffset, YOffset, ScaleX, and ScaleY as resolved by any prior BBCode tags on the same letter. Functions using the simple two-parameter signature continue to work unchanged.

Last updated

Was this helpful?