How to Play Gum Screen Animations


Gum screens support animations which can be played through code. This article shows how to access a Gum animation and play it in your FlatRedBall project.


To access a Gum screen in code you must first create an object in Glue for the Gum screen. For information on how to do this, see this article. Animations can be defined in Gum or in code. To define an animation in Gum, see the Gum Usage Guide.

Accessing animations in code

// Assuming the object is called "GumScreen":

Playing Animations on Component Instances

Similar to screens, components can also contain animations which can be played at runtime. To play an animation on a component at runtime:

  1. Add an animation to a Gum component

  2. Obtain a reference to the component at runtime. For example, get a reference from a Gum screen in a Glue screen's Objects.

  3. Call the Play method on the desired animation within the component instance in code. For example, if the ButtonRuntime has an animation called FadeOutAnimation, the following code could be used to play the animation:


GumAnimation Details

All animations are instances of the GumAnimation class, which provides useful variables, methods, and events.

EndReached Event

The EndReached event is raised by the animation after the animation reaches its end (which is defined by its Length property). To use the EndReached event, you can add an Action to it, as follows:

void CustomInitialize()
    // Assign the event somewhere, like in CustomInitialize of a screen or entity:
    Button.FadeOutAnimation.EndReached += HandleEndReached;

// Implement the HandleEndReached method:
void HandleEndReached()
   // The animation ended, so do whatever, like play a sound

Last updated