Animation

Introduction

AnimationRuntime is a class containing a list of keyframes (of type KeyframeRuntimeInstance). AnimationRuntime instances can be used to modify variables on a GraphicalUiElement over time .

AnimationRuntime instances can be created from animations defined in the Gum tool or by hand in code. For information on how to create an animation in the Gum Tool, see the Animation Tutorials section.

Code Example - Loading Animations from Gum Project

Animations defined in the Gum tool can be loaded at runtime. To load and play an animation, the following calls are needed:

  1. Call GumService.LoadAnimations . This loads all animation files for all screens and components in the current Gum project.

  2. Obtain an AnimationRuntime instance from your GraphicalUiElement . This could be a screen or component.

  3. Call PlayAnimation to begin the animation.

Animations can be played on an entire screen, entire component, or an individual instance within a screen or component.

For this example, the project has a screen called AnimatedScreen which contains an animation named SlideOnAndOff.

AnimatedScreen also contains an instance of a component named PleaseWaitPopup which has its own animation called Spinning. Note that the Spinning animation is marked as repeating, so once it starts it will play until it is stopped in code.

The following code shows how to load all animations, create the AnimatedScreen, and play animations according to keyboard commands.

Code Example - Animations in Code-Only Projects

Animations can be defined and executed in a code-only environment. The steps for creating an animation in a code only project are:

  1. Creating an object which will be animated (such as a Button).

  2. Creating the states for the animation. For example, a Button may have a larger size when highlighted, and a smaller size when not highlighted.

  3. Create keyframes which define the time when each state should display and how to interpolate (tween) between each of the keyframes.

  4. Define the animation using the states (keyframes) defined earlier.

  5. Play the animation in response to an event, such as a Button highlight.

Button reacting to hover

Playing Multiple Animations on the Same Instance

The PlayAnimation method performs the following logic:

  1. Internally stores the animation that is played

  2. Internally resets the time on the animation back to 0

Each instance can store a separate animation and time, allowing a single animation to be played on multiple instances.

Since each instance only stores one value for the current animation and time, an instance cannot play multiple animations at one time.

Future versions of Gum may change this behavior, allowing PlayAnimation to stack multiple animations.

To play multiple animations, we can keep track of each animation time and apply it manually in our update function.

The following code assumes that Animation1 and Animation2 are valid animations. The following code also assumes that MyInstance is a valid visual instance.

Last updated

Was this helpful?