The Clone method can be used to make a copy of the AnimationChainList. This method is useful if your game needs to make copies of AnimationChainLists loaded from file. This is the case if the AnimationChainLists use the same texture coordinates, but simply use different Textures (such as different animation chains for characters in a game).
The following code example assumes that OriginalAnimationChainList is a valid AnimationChainList.
For more information see the AddDisposable page.
The FrameToFrame method returns the shortest absolute distance between two frame indexes. This value may be negative and considers looping. Example Assuming you have created an AnimationChain named "ac" with 6 AnimationFrames (the last at index 5), FrameToFrame returns the following values:
Call
Result
Explanation
ac.FrameToFrame(1, 2)
1
The closest distance from 1 to 2 is 1 frame.
ac.FrameToFrame(2, 1)
-1
The closest distance from 2 to 1 is -1. This value is negative because you must move "backward" to get from 2 to 1
ac.FrameToFrame(1, 5)
-2
The closest distance considering looping to get from 1 to 5 is -2. That is first going from 1 to 0, then 0 to 5 (the last frame)
ac.FrameToFrame(0, 3)
3
Although 0 is both 3 and -3 frames away from index 3, FrameToFrame doesn't wrap if the direct difference is equally short as the wrapped.
The total length obtained by adding the FrameTimes of all contained AnimationFrames.
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.
AnimationChains can be created manually by creating the frames individually through code, by loading a .achx file, or through the content pipeline.
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.
For information on loading an AnimationChainList from a .achx file, see this page.
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 :
FlatRedBall.Graphics.Animation.AnimationFrame - AnimationChains represent a list of AnimationFrames. When an AnimationChain is applied to an object, the object flips through and uses the AnimationFrames to modify its appearance.
FlatRedBall.Graphics.Animation.AnimationChainList - AnimationChainLists are lists of AnimationChains. Objects such as Sprites store AnimationChainLists, simplifying the process of setting which AnimationChain is currently used.
FlatRedBall.Content.AnimationChain.AnimationChainListSave - The "save" file for AnimationChainList files. This can be saved to and loaded from .achx files, and can also be converted to and from AnimationChainLists. For more information, see the FlatRedBall File Types wiki entry.
FlatRedBall.Graphics.Animation.IAnimationChainAnimatable - The interface that defines properties and members for objects which can be animated by AnimationChains. See this article for information on how to set animations on objects such as Sprites.
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.