Skip to content

Animation

namespace Griff.Scenes;
public sealed class Animation : Component

Plays 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.

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.

public IReadOnlyList<AnimationClip> ClipList { get; }

The parsed Clips.

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.

public bool Finished { get; }

True once a non-looping animation has shown its last frame.

public int FirstFrame { get; set; }

The sheet’s frame it starts on, counting from 0 along the top row, then the next.

public int FrameCount { get; set; }

How many frames it plays, from FirstFrame on.

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.

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.

public void Advance(float seconds)

Advances time and sets the sprite’s frame. Called by the game every frame.

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.

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.

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.

public bool HasClip(string clip)

True if Clips has one called clip (names ignore case).

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.

public bool PlaysBackward(string? clip)

Whether the clip called clip plays from its last frame down to its first (“3-0”).