Animation
namespace Griff.Scenes;
public sealed class Animation : ComponentPlays frames of the entity’s sprite sheet: FrameCount frames starting at FirstFrame. For several animations on one sheet, name them in Clips and switch with Play.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”public string? Clip { get; set; }The clip playing, by name, e.g. “Idle”. While it names one of Clips, its frames are shown instead of FirstFrame and FrameCount. Set it in the Inspector to pick the clip the game starts with.
ClipList
Section titled “ClipList”public IReadOnlyList<AnimationClip> ClipList { get; }The parsed Clips.
ClipNames
Section titled “ClipNames”public IReadOnlyList<string> ClipNames { get; }The names of its Clips, in order: what Clip can name.
public string? Clips { get; set; }Named animations on the sprite sheet, separated by commas: a name, a frame or range of frames, and optionally a speed and whether it plays once, e.g. Idle 0-3, Run 4-9 @12, Jump 10, Die 11-15 @8 once. A range written high to low plays backward: Open 0-3 once, Close 3-0 once.
Finished
Section titled “Finished”public bool Finished { get; }True once a non-looping animation has shown its last frame.
FirstFrame
Section titled “FirstFrame”public int FirstFrame { get; set; }The sheet’s frame it starts on, counting from 0 along the top row, then the next.
FrameCount
Section titled “FrameCount”public int FrameCount { get; set; }How many frames it plays, from FirstFrame on.
FramesPerSecond
Section titled “FramesPerSecond”public float FramesPerSecond { get; set; }How fast it plays, in frames per second.
public bool Loop { get; set; }Starts over after the last frame; off stops on it.
Playing
Section titled “Playing”public bool Playing { get; set; }Whether it’s playing now; off holds the frame it’s on.
public float Time { get; set; }Seconds into the current animation; restart by setting to 0. Kept with the scene, so a rewind or a saved game comes back to the frame it was on (and the boxes of a Hitboxes with it); give a row of torches different times so they don’t flicker in step.
Methods
Section titled “Methods”Advance
Section titled “Advance”public void Advance(float seconds)Advances time and sets the sprite’s frame. Called by the game every frame.
ClipSettings
Section titled “ClipSettings”public ValueTuple<int, int, float, bool> ClipSettings(string? clip)The frames, speed and looping the clip called clip plays with: its own, with the animation’s speed and looping where it leaves them out. With no clip of that name (or none named), the animation’s own FirstFrame and FrameCount.
FormatClips
Section titled “FormatClips”public static string FormatClips(IEnumerable<AnimationClip> clips)Writes clips the way Clips holds them, e.g. Idle 0-3, Run 4-9 @12, Die 11-15 once: what ParseClips reads back.
FrameAt
Section titled “FrameAt”public static int FrameAt(float time, int count, float framesPerSecond, bool loop)Which of a clip’s count frames shows time seconds in, counting from 0: a looping clip goes round again, one that plays once stays on its last frame.
HasClip
Section titled “HasClip”public bool HasClip(string clip)True if Clips has one called clip (names ignore case).
ParseClips
Section titled “ParseClips”public static IReadOnlyList<AnimationClip> ParseClips(string? text)Reads clips written like Clips. Entries that don’t make sense (no name, or no frames) are skipped, so a half-typed list still plays what it can.
public void Play(string clip, bool restart = false)Switches to the clip called clip from the start, and plays it. Playing the clip that’s already playing carries on (so it’s safe to call every frame) unless restart is set.
PlaysBackward
Section titled “PlaysBackward”public bool PlaysBackward(string? clip)Whether the clip called clip plays from its last frame down to its first (“3-0”).