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.
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: Then this animation can be accessed in code:
Similar to screens, components can also contain animations which can be played at runtime. To play an animation on a component at runtime:
Add an animation to a Gum component
Obtain a reference to the component at runtime. For example, get a reference from a Gum screen in a Glue screen's Objects.
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:
All animations are instances of the GumAnimation class, which provides useful variables, methods, and events.
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:
Gum objects support playing .achx animations. This enables the use of the familiar AnimationEditor to create texture-based animations for Gum objects. Note that AnimationChain animations are used to change texture or texture coordinates. These are typically used for animated characters in 2D games. AnimationChain animations cannot change the size, orientation, or other common Gum properties.
Glue Version 12 introduces automatic calling of AnimateSelf on the top-level Gum screen. If your Glue project is using an earlier version than version 12, you will need to explicitly add the following to your CustomActivity:
For more information on Glue versions, see the gluj/glux page.
For this example we will assume a Sprite named SpriteInstance.
This Sprite is contained in a page named MainMenuGum which is assumed to be inside a FlatRedBall Screen named MainMenu.
We can set the Sprite to be animated using the following code in CustomInitialize:
The Gum Sprite now animates when running the game.
Named events can be used to perform custom logic at certain times in an animation. Since named events are created in Gum, the animator can align the performance of logic visually. For example, a Gum animation may be used to move components of a title screen into view. While this animation is playing the game may need to play sound effects and music at certain times. Named events can be used to play music and sound effects at certain times.
Named events can be added to animations in Gum in the animation window. To add a named event to an existing animation:
Select the animation
Click the Add Named Event button
Enter a name for the event
Select the event
Enter a time for the event
Gum animations have an AddAction method which can be used to add custom actions at certain times: For example, if the screen were accessible in code as GameScreenGumRuntime in a Glue screen, the MakeYellow named event could be reacted to as shown in the following code: