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

MaxLettersToShow

Introduction

MaxLettersToShow controls the number of letters that are displayed by a TextRuntime. This value can be used to print text out letter-by-letter. This property does not change alignment or size of text. In other words, a TextRuntime with its WidthUnits or HeightUnits of RelativeToChildren reports the same absolute width regardless of its MaxLettersToShow value.

Code Example - Printing Letters One at a Time

The following code can be used to print letters out one at a time. deltaSeconds is your framework's frame time in seconds.

// Class scope
TextRuntime textRuntime;
bool isPrinting = false;
float numberOfCharacters;

// Initialize
textRuntime = new TextRuntime();
textRuntime.AddToRoot();
textRuntime.Text = "This is longer text which is used to " +
    "create word wrapping. Notice that when this prints out, " +
    "it prints one letter at a time and wraps according to the " +
    "TextRuntime's bounds";

textRuntime.Anchor(Anchor.Center);
textRuntime.Width = 200;
textRuntime.WidthUnits = Gum.DataTypes.DimensionUnitType.Absolute;
textRuntime.Height = 0;
textRuntime.HeightUnits = Gum.DataTypes.DimensionUnitType.RelativeToChildren;
textRuntime.MaxLettersToShow = 0;

// Update
GumUI.Update(gameTime);

if(GumUI.Keyboard.KeyPushed(Gum.Forms.Input.Keys.Space))
{
    isPrinting = true;
    numberOfCharacters = 0;
}

if(isPrinting)
{
    const int charactersPerSecond = 20;
    numberOfCharacters += 
        (float)deltaSeconds * charactersPerSecond;

    textRuntime.MaxLettersToShow = (int)numberOfCharacters;
}

Last updated

Was this helpful?