Ss14 graphics animation player

From space-sunrise/lust-station · View interactive version

Ss14 graphics animation player is an AI agent skill from the GitHub repository space-sunrise/lust-station. A deep practical guide to entity animations using the AnimationPlayerSystem in SS14: lifecycle, API, track types, keyframes/interpolation/easing, completion events, patterns and anti-patterns for production code.

How to use this skill

Skill file

Animations via AnimationPlayer in SS14

This skill only covers entity animations via AnimationPlayerSystem :)

UI animations (Control.PlayAnimation) and shader/overlay effects are handled in separate skills.

When to use

Choose AnimationPlayerSystem when needed:

Don't use it for static visual states without time: this is the normal SpriteSystem/GenericVisualizer zone.

Mental model

  1. You create Animation (Length + list AnimationTracks).
  2. You play it through AnimationPlayerSystem.Play(...) under the unique key.
  3. The system moves the playback every frame and applies the track values.
  4. Upon completion, AnimationCompletedEvent (Finished = true) arrives.
  5. When manually stopping Stop(...) also comes AnimationCompletedEvent, but Finished = false.

Idea: animation is a local timeline of the effect, not network business logic :)

Important client/server boundary

API parsing `AnimationPlayerSystem`

Launch

Practice:

Checking running

Stop

The stop triggers a completion event with Finished = false.

Events

Structure `Animation`

Rule: Length must cover all the necessary key phases of the tracks.

Types of tracks and when to take which one

`AnimationTrackComponentProperty`

Changes the component property by keyframes.

Required fields:

Use for:

`AnimationTrackSpriteFlick`

Controls the RSI-state of the layer over time.

Required fields:

Use it when you need to play the state animation of the layer.

`AnimationTrackPlaySound`

Plays sound on the given keyframes.

Use for precise synchronization of “visual + sound” in one timeline.

KeyFrame and interpolation

AnimationTrackProperty.KeyFrame(value, keyTime, easing?):

AnimationInterpolationMode:

For unsupported types, interpolation actually behaves like a discrete step (previous value).

Practical examples

Example 1: secure launch by key

private const string AnimKey = "rotating_light";

private void TryPlayRotation(EntityUid uid, AnimationPlayerComponent player, Animation anim)
{
    // We do not allow key conflicts in PlayingAnimations.
    if (_anim.HasRunningAnimation(uid, player, AnimKey))
        return;

    _anim.Play((uid, player), anim, AnimKey);
}

Example 2: correct stop + cleanup

private void StopFallAnimation(EntityUid uid, AnimationPlayerComponent player, SpriteComponent sprite, Vector2 originalScale)
{
    // First, we return the visual parameters to their basic state.
    _sprite.SetScale((uid, sprite), originalScale);

    // Then we stop the animation by key.
    _anim.Stop((uid, player), "chasm_fall");
}

Example 3: property-track with easing

private static Animation BuildPickupAnim(Vector2 from, Vector2 to, Color startColor)
{
    return new Animation
    {
        Length = TimeSpan.FromMilliseconds(175),
        AnimationTracks =
        {
            new AnimationTrackComponentProperty
            {
                ComponentType = typeof(TransformComponent),
                Property = nameof(TransformComponent.LocalPosition),
                InterpolationMode = AnimationInterpolationMode.Linear,
                KeyFrames =
                {
                    // keyTime - delta from the previous keyframe.
                    new AnimationTrackProperty.KeyFrame(from, 0f),
                    new AnimationTrackProperty.KeyFrame(to, 0.175f, Easings.OutQuad)
                }
            },
            new AnimationTrackComponentProperty
            {
                ComponentType = typeof(SpriteComponent),
                Property = nameof(SpriteComponent.Color),
                KeyFrames =
                {
                    new AnimationTrackProperty.KeyFrame(startColor, 0f),
                    new AnimationTrackProperty.KeyFrame(startColor.WithAlpha(0f), 0.175f, Easings.OutQuad)
                }
            }
        }
    };
}

Example 4: combined track (flick + light)

private static readonly Animation ProximityAnim = new()
{
    Length = TimeSpan.FromSeconds(0.6f),
    AnimationTracks =
    {
        new AnimationTrackSpriteFlick
        {
            LayerKey = ProximityTriggerVisualLayers.Base,
            KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame("flashing", 0f) }
        },
        new AnimationTrackComponentProperty
        {
            ComponentType = typeof(PointLightComponent),
            Property = nameof(PointLightComponent.AnimatedRadius),
            InterpolationMode = AnimationInterpolationMode.Nearest,
            KeyFrames =
            {
                new AnimationTrackProperty.KeyFrame(0.1f, 0f),
                new AnimationTrackProperty.KeyFrame(3f, 0.1f),
                new AnimationTrackProperty.KeyFrame(0.1f, 0.5f)
            }
        }
    }
};

Example 5: manual loop via `AnimationCompletedEvent`

private void OnAnimationCompleted(EntityUid uid, RotatingLightComponent comp, AnimationCompletedEvent args)
{
    if (args.Key != "rotating_light")
        return;

    // We re-beat only at natural completion.
    if (!args.Finished)
        return;

    if (!TryComp<AnimationPlayerComponent>(uid, out var player))
        return;

    _anim.Play((uid, player), BuildRotation(comp.Speed), "rotating_light");
}

Example 6: flick with infinite length + sound

private Animation BuildPrimingAnimation(ResolvedSoundSpecifier? sound)
{
    var anim = new Animation
    {
        Length = TimeSpan.MaxValue,
        AnimationTracks =
        {
            new AnimationTrackSpriteFlick
            {
                LayerKey = TriggerVisualLayers.Base,
                KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame("primed", 0f) }
            }
        }
    };

    if (sound != null)
    {
        anim.AnimationTracks.Add(new AnimationTrackPlaySound
        {
            KeyFrames = { new AnimationTrackPlaySound.KeyFrame(sound.Value, 0f) }
        });
    }

    return anim;
}

Example 7: Animate a color without duplicating a component

private Animation BuildColorFlash(Color from, Color to, float seconds)
{
    return new Animation
    {
        Length = TimeSpan.FromSeconds(seconds),
        AnimationTracks =
        {
            new AnimationTrackComponentProperty
            {
                ComponentType = typeof(SpriteComponent),
                Property = nameof(SpriteComponent.Color),
                InterpolationMode = AnimationInterpolationMode.Linear,
                KeyFrames =
                {
                    new AnimationTrackProperty.KeyFrame(from, 0f),
                    new AnimationTrackProperty.KeyFrame(to, seconds)
                }
            }
        }
    };
}

Example 8: connection with appearance without spam

private void UpdateTriggeredState(EntityUid uid, AnimationPlayerComponent player, ProximityTriggerVisuals state)
{
    switch (state)
    {
        case ProximityTriggerVisuals.Active:
            if (!_anim.HasRunningAnimation(uid, player, "proximity"))
                _anim.Play((uid, player), ProximityAnim, "proximity");
            break;
        case ProximityTriggerVisuals.Inactive:
        case ProximityTriggerVisuals.Off:
            _anim.Stop((uid, player), "proximity");
            break;
    }
}

Patterns 🙂

Anti-patterns ❌

Checklist before change ✅

Common errors

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.