AnimationChains represent a series of AnimationFrames which can be used to animate objects which implement the IAnimationChainAnimatable interface such as Sprites. AnimationChains can be created in code, or they can be created using the AnimationEditor. The AnimationEditor is installed when running the FlatRedBall installer which can be found on the downloads page. The IAnimationChainAnimatable page has more information on how to use AnimationChains, so please check it out after finishing up this page.


The following statement will help reduce code when working with AnimationChains.

using FlatRedBall.Graphics.Animation;

Creating AnimationChains

AnimationChains can be created manually by creating the frames individually through code, by loading a .achx file, or through the content pipeline.

Creating AnimationChains in Code

AnimationChain animationChain = new AnimationChain();
animationChain.Add(new AnimationFrame(@"Animation\Drone_0000.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0001.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0002.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0003.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0004.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0005.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0006.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0007.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0008.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0009.png", .1f, "Global"));
animationChain.Add(new AnimationFrame(@"Animation\Drone_0010.png", .1f, "Global"));

Notice that the .1f is the frame length in seconds. For from-file and content pipeline loading, see the AnimationChainList wiki entry.

Note: The AnimationFrame class is used to define individual frames in an AnimationChain. For more information on how to modify your animations, including how to create animations by using parts of a single Texture, see the AnimationFrame page.

Loading an AnimationChainList from file

For information on loading an AnimationChainList from a .achx file, see this page.

Accessing AnimationFrames

AnimationChains are also Lists of AnimationFrames. Therefore the AnimationChain provides the same interface as a list for accessing frames, such as indexing ( [index] ), properties like Count, and methods like Add. For example, the following code can be used to change the referenced texture of all frames in an animation chain to NewTexture :

foreach(var frame in AnimationChainInstance)
   frame.Texture = NewTexture;

AnimationChain Members

Additional Information

  • FlatRedBall.Sprite.PixelSize - PixelSize can be used to reactively set scale based off of a changed Texture resulting from playing an AnimationChain.

Did this article leave any questions unanswered? Post any question in our forums for a rapid response.

Last updated