> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/gum/animations/gum-how-to-play-gum-screen-animations.md).

# How to Play Gum Screen Animations

### Introduction

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.

### Setup

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](/flatredball/gum/how-to-work-with-screens-in-code.md). Animations can be defined in Gum or in code. To define an animation in Gum, see the [Gum Usage Guide](https://flatredball.gitbook.io/gum/animation-tutorials/creating-an-animation).

### Accessing animations in code

Animations added to Gum screens can be accessed in code. The Glue code generator will append the word "Animation" to animation names. For example, consider a Gum screen containing an animation called MoveToRight: ![MoveToRightAnimationInGum.PNG](/files/ZDimCmYYty5CuHqsvBGA) Then this animation can be accessed in code:

```
// Assuming the object is called "GumScreen":
GumScreen.MoveToRightAnimation.Play();
```

### 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.

   ![](/files/rIzCxnKSPnpbHSm0khWU)
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:

```lang:c#
ButtonInstance.FadeOutAnimation.Play();
```

### 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:

```lang:c#
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
   BeepSound.Play();
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flatredball.com/flatredball/gum/animations/gum-how-to-play-gum-screen-animations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
