> 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](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-860d78340f03f27833a4112d810bf3649b829fcc%2Fmigrated_media-MoveToRightAnimationInGum.PNG?alt=media) 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.

   ![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-ed7de1891d7cd177e1e2800f76668c84f8104c60%2F2017-06-img_594c7ea4b26f7.png?alt=media)
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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
