Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

feat(video): an attack is one 2 s strike, and its whole clip is the loop

Soohong Kimd62b6184b585
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 3cb2dca..442e4f8 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -82,22 +82,27 @@ stance … same height every time"). `video-set` carries those templates
name limbs — the first drafts said "bipedal … knees … arms pumping", which prompted a
quadruped and a legless blob into a contradiction (2026-09-09).
-An attack is a timed strike, not a repeat. `MOTION_TEXT["attack"]` asks for the same attack
-twice, each a windup (about 0.5 s), one strike in front (about 0.25 s), a held impact pose
-(about 0.3 s) and a recovery to the exact starting stance (about 0.5 s), then `HOLD_TEXT["attack"]`:
+An attack is one timed strike, not a repeat. `MOTION_TEXT["attack"]` asks for one attack: a windup
+(about 0.5 s), one strike in front (about 0.25 s), a held impact pose (about 0.3 s) and a recovery
+to the exact starting stance (about 0.5 s), then `HOLD_TEXT["attack"]`:
every grip stays the one the image shows — one hand stays one hand, both hands stay both hands,
nothing let go or switched to the other hand — a hand the strike does not use stays where it is
drawn with whatever it holds (a shield, a lantern), and the body never turns. Naming one hand
for a weapon the still draws in both hands made the clip let go and grab again mid-attack.
A caller's own motion paragraph (`build_prompt(motion=...)`) gets the same `HOLD_TEXT` sentence
-after it, once, then `REPEAT_TEXT`: a request interpreter writes its motion before the still
+after it, once: a request interpreter writes its motion before the still
exists and cannot know where the other hand's item is drawn, so it writes the choreography and
the engine says what stays put. Its template
(`ACTION_COMMON_TEXT`) drops the "evenly paced" line, keeps what the subject holds inside the
-frame, and asks for crisp frames without motion blur. `video-set` asks attack clips for 4 s
+frame, and asks for crisp frames without motion blur. `video-set` asks attack clips for 2 s
(`STATE_DURATION_SECONDS`; every other state keeps 3 s, and `--duration` overrides every state)
and pins the clip to end on the frame it starts from: `--last-frame` is the canvas itself
-(first-last mode, see [video.md](video.md)), so the strike has to come back to the still.
+(first-last mode, see [video.md](video.md)), so the strike has to come back to the still. That
+clip is stance -> strike -> stance, so it is cut whole like an idle (`--cycle pinned`,
+`PINNED_LOOP_STATES`): the loop starts on the ready stance and never is a fragment of the strike
+or a seam between two strikes. Asked for the same attack twice and cut by the one-shot or period
+search, a clip gave loops that started mid-strike, held both strikes, or kept only the held pose;
+asked for one attack in 3 or 4 s, it held the impact pose for about half the clip.
An idle holds its feet and is pinned too. `MOTION_TEXT["idle"]` keeps both feet planted flat for
the whole clip, limits the motion to breathing, a settle of the arms, hair and loose cloth and
@@ -112,7 +117,7 @@ it for a repeat.
`build_prompt(direction, state, character, facing, motion=...)` takes a caller's own motion
paragraph — whole sentences about the subject, such as a request interpreter writes per
request — in place of the built-in state sentence. The frame, camera, background and design
-rules stay the engine's, and an attack keeps its "twice in a row" sentence.
+rules stay the engine's, and an attack keeps its `HOLD_TEXT` sentence after the paragraph.
## 3. Frames — extract, key, check the edges
@@ -401,8 +406,8 @@ Outputs:
runs canvas → video → frames → loop for every (direction, state). The xAI team quota
is **2 requests per second** (five parallel starts produced two HTTP 429s): starts are
staggered (`--start-gap 2`) and a 429 gets a bounded, logged retry (15 s, 30 s). Clip length
-is each state's own default (3 s, attack 4 s) unless `--duration` sets one for all, and an
-attack or idle clip is pinned to end on its canvas (an idle is then cut whole, `--cycle pinned`). States use differently shaped canvases (square, tall, wide),
+is each state's own default (3 s, attack 2 s) unless `--duration` sets one for all, and an
+attack or idle clip is pinned to end on its canvas and cut whole (`--cycle pinned`). States use differently shaped canvases (square, tall, wide),
so the same character films at different pixel heights; `--body-height N` gives every state's loop the
same standing-height target and keeps the character one size across the set. At a low
`--resolution`, `--fit tight` frames every item without room so that target is reached by
diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.py
index e848e49..da2ab05 100644
--- a/sprite_gen/video/batch.py
+++ b/sprite_gen/video/batch.py
@@ -35,18 +35,21 @@ START_GAP_SECONDS = 2.0
# for jump/attack, which the one-shot cut handles; 6 s bought nothing but a longer wait
# and, for jump, more idle standing between hops.
DEFAULT_DURATION_SECONDS = 3
-# An attack is timed rather than repeated: a windup, one strike, a held impact pose and the
-# recovery, twice. Four seconds holds both attacks at the stated timing; a shorter clip squeezes
-# them, a longer one stretches them.
-STATE_DURATION_SECONDS = {"attack": 4}
+# An attack is one timed strike: a windup, the strike, a held impact pose and the recovery, about
+# 1.6 s at the stated timing. Two seconds holds it with the stance on either side; asked for 3 or
+# 4 s, the clip still struck once and held the impact pose for about half of it.
+STATE_DURATION_SECONDS = {"attack": 2}
# States whose clip is pinned to end on the frame it starts from (first-last mode): the model
# has to come back to the still, which closes a one-shot action instead of leaving it wherever
# the strike ended, and closes an idle without asking for a repeating rhythm.
PIN_LAST_FRAME_STATES = frozenset({"attack", "idle"})
# Pinned states whose whole clip is the loop: it starts and ends on the canvas, so `video-loop
-# --cycle pinned` keeps every frame but the last (a re-render of the first). An attack is
-# pinned too but is cut as the one-shot it is.
-PINNED_LOOP_STATES = frozenset({"idle"})
+# --cycle pinned` keeps every frame but the last (a re-render of the first). An attack asked
+# for once is ready stance -> strike -> ready stance, so its whole clip is one attack too.
+PINNED_LOOP_STATES = frozenset({"idle", "attack"})
+# States filmed as a fast action (`ACTION_COMMON_TEXT`): crisp frames, what they hold kept inside
+# the frame, and no "evenly paced" line.
+ACTION_TEXT_STATES = frozenset({"attack"})
RETRY_BACKOFF_SECONDS = (15, 30)
@@ -81,10 +84,10 @@ MOTION_TEXT = {
"run": "moves in place on a treadmill: a fast locomotion cycle for this body type with a bounding rhythm and clear repeating ground contacts.",
"jump": "performs a modest vertical hop in place over and over: compress, spring up about half the body height, land softly, return to the exact starting stance, repeat at an even rhythm. Same height every time.",
"attack": (
- "performs the same melee attack twice in a row with what it is already holding (bare hands only if it holds "
- "nothing), keeping every piece of its gear and outfit exactly as drawn. Each attack is a windup (about 0.5 s), "
- "one clean strike in front (about 0.25 s), a held impact pose (about 0.3 s), then a recovery to the exact "
- "starting stance (about 0.5 s). " + HOLD_TEXT["attack"]
+ "performs one melee attack with what it is already holding (bare hands only if it holds nothing), keeping "
+ "every piece of its gear and outfit exactly as drawn: a windup (about 0.5 s), one clean strike in front "
+ "(about 0.25 s), a held impact pose (about 0.3 s), then a recovery to the exact starting stance (about 0.5 s). "
+ + HOLD_TEXT["attack"]
),
"cheer": "celebrates in place: rises into a raised, spread-out cheer pose, holds it for a beat, then settles back to the exact starting stance, repeating at an even rhythm.",
"wave": "waves in place: lifts one side into a friendly wave, sways it a few times, then settles back to the exact starting stance, repeating at an even rhythm.",
@@ -114,9 +117,9 @@ ACTION_COMMON_TEXT = (
"for the whole clip — no shadows, no ground line, no particles, no lighting changes, no effects. Keep the design, "
"colors and proportions exactly as in the image. Crisp, clean frames with no motion blur, no smears and no afterimages."
)
-# A caller's own motion paragraph (`build_prompt(motion=...)`) says what one attack is; this says
-# how many to make, the same count the built-in attack text asks for.
-REPEAT_TEXT = {"attack": "Perform this attack twice in a row with the same timing each time."}
+# How many times a caller's own motion paragraph (`build_prompt(motion=...)`) is performed, for
+# states that repeat it. An attack is performed once: its pinned clip is the loop.
+REPEAT_TEXT: dict[str, str] = {}
_start_lock = threading.Lock()
_last_start = [0.0]
@@ -140,10 +143,10 @@ def build_prompt(direction: str, state: str, character: str | None, facing: str
"""
validate_facing(facing)
view = VIEW_TEXT.get(direction, f"seen from the {direction}").format(facing=facing)
- if state in PINNED_LOOP_STATES:
- template = PINNED_LOOP_TEXT
- elif state in PIN_LAST_FRAME_STATES:
+ if state in ACTION_TEXT_STATES:
template = ACTION_COMMON_TEXT
+ elif state in PINNED_LOOP_STATES:
+ template = PINNED_LOOP_TEXT
else:
template = COMMON_TEXT
if motion is not None:
diff --git a/tests/video/test_attack_motion.py b/tests/video/test_attack_motion.py
index 267f7c0..4d97435 100644
--- a/tests/video/test_attack_motion.py
+++ b/tests/video/test_attack_motion.py
@@ -1,4 +1,4 @@
-"""Attack clips: a timed strike twice, the drawn grip, no turning, pinned to end where they start.
+"""Attack clips: one timed strike, the drawn grip, no turning, pinned to end where they start.
A 4 s clip, the frame, camera and background rules without the "evenly paced" line, and a
caller's own motion paragraph (`build_prompt(motion=...)`) in place of the built-in one.
@@ -16,9 +16,9 @@ from sprite_gen.video import batch as batch_mod
FIXTURE = Path(__file__).parents[1] / "fixtures" / "facing" / "left.png"
-def test_attack_text_is_timed_keeps_the_drawn_grip_and_is_twice() -> None:
+def test_attack_text_is_one_timed_strike_that_keeps_the_drawn_grip() -> None:
text = batch_mod.build_prompt("side", "attack", None)
- for phrase in ("twice in a row", "Every grip stays exactly as shown in the image", "one hand stays one hand, both hands stay both hands",
+ for phrase in ("one melee attack", "Every grip stays exactly as shown in the image", "one hand stays one hand, both hands stay both hands",
"windup (about 0.5 s)", "strike in front (about 0.25 s)", "held impact pose (about 0.3 s)",
"exact starting stance", "nothing is let go or switched to the other hand",
"A hand the motion does not use stays where it is drawn, with anything it holds",
@@ -29,6 +29,8 @@ def test_attack_text_is_timed_keeps_the_drawn_grip_and_is_twice() -> None:
assert text.count("stays exactly as shown") == 1 and text.count("without turning") == 1
# the grip is the image's: a heavy weapon drawn in both hands is not asked into one
assert "hand nearest the viewer" not in text
+ # one strike: the whole pinned clip is the loop, so nothing asks for a second one
+ assert "twice" not in text and "Perform this attack" not in text
assert "evenly paced" not in text
# the repeating states keep their template, evenly paced line included
assert "evenly paced" in batch_mod.build_prompt("side", "walk", None)
@@ -39,7 +41,7 @@ def test_a_callers_motion_replaces_the_built_in_sentence() -> None:
motion = "The knight draws the sword back, then strikes forward and holds the impact pose. It never turns."
text = batch_mod.build_prompt("side", "attack", "A small knight.", facing="right", motion=motion)
hold = batch_mod.HOLD_TEXT["attack"]
- assert text.startswith(f"2D game sprite animation. {motion} {hold} Perform this attack twice in a row with the same timing each time. "
+ assert text.startswith(f"2D game sprite animation. {motion} {hold} "
"A small knight is seen from the exact side, facing right. Stays centered")
assert text.endswith("no motion blur, no smears and no afterimages.")
assert "melee attack" not in text # the built-in attack sentence is not added on top
@@ -68,8 +70,8 @@ def test_video_cli_pins_the_last_frame_only_when_asked(tmp_path: Path, monkeypat
assert seen[1][seen[1].index("--duration") + 1] == "4"
[email protected]("state,duration,pinned", [("attack", 4, True), ("jump", 3, False)])
-def test_video_set_pins_attack_to_its_canvas_for_four_seconds(tmp_path: Path, state: str, duration: int, pinned: bool, monkeypatch) -> None:
[email protected]("state,duration,pinned", [("attack", 2, True), ("jump", 3, False)])
+def test_video_set_pins_attack_to_its_canvas_for_two_seconds(tmp_path: Path, state: str, duration: int, pinned: bool, monkeypatch) -> None:
monkeypatch.setattr(batch_mod.facing_mod.vision, "grok_inspect", lambda *a, **kw: ("right", {}))
calls: list[dict] = []
@@ -93,6 +95,7 @@ def test_video_set_pins_attack_to_its_canvas_for_four_seconds(tmp_path: Path, st
def test_video_set_gives_every_state_the_same_body_height(tmp_path: Path, monkeypatch) -> None:
from PIL import Image
seen: list = []
+ cycles: dict = {}
def fake_canvas(base, out, *, state, shape, facing, headroom, lead, report_path, fit="state"):
Image.new("RGB", (32, 32), (0, 255, 0)).save(out)
@@ -105,6 +108,7 @@ def test_video_set_gives_every_state_the_same_body_height(tmp_path: Path, monkey
def fake_loop(frames_dir, out_dir, **kw):
seen.append((kw["state"], kw.get("body_height")))
+ cycles[kw["state"]] = kw.get("cycle_mode")
return {"cycle": {"kind": "periodic", "length": 24, "period_global": 24, "ratio": 0.2}, "resampled_seam_ratio": 0.3,
"n_out": 8, "gif": {"file": "g"}, "webp": {"file": "w"}, "strip": {"path": "s", "drift_px": 0}}
@@ -124,6 +128,8 @@ def test_video_set_gives_every_state_the_same_body_height(tmp_path: Path, monkey
video_runner=video, body_height=300)
assert payload["ok"] == 2 and payload["body_height"] == 300
assert sorted(seen) == [("attack", 300), ("walk", 300)]
+ # one strike, pinned: the attack's whole clip is its loop; a walk still searches its period
+ assert cycles == {"attack": "pinned", "walk": "auto"}
import argparse
parser = argparse.ArgumentParser()
batch_mod.add_arguments(parser)
diff --git a/tests/video/test_duration_window_oneshot.py b/tests/video/test_duration_window_oneshot.py
index 2d0b800..ab3a126 100644
--- a/tests/video/test_duration_window_oneshot.py
+++ b/tests/video/test_duration_window_oneshot.py
@@ -42,7 +42,7 @@ def test_video_set_duration_defaults_per_state(monkeypatch) -> None:
assert seen["duration"] is None
assert batch_mod.DEFAULT_DURATION_SECONDS == 3
assert batch_mod.duration_for("walk", None) == batch_mod.duration_for("jump", None) == 3
- assert batch_mod.duration_for("attack", None) == 4
+ assert batch_mod.duration_for("attack", None) == 2
assert batch_mod.duration_for("attack", 6) == batch_mod.duration_for("walk", 6) == 6
diff --git a/tests/video/test_idle_still.py b/tests/video/test_idle_still.py
index b1acd38..6a33ebd 100644
--- a/tests/video/test_idle_still.py
+++ b/tests/video/test_idle_still.py
@@ -30,10 +30,10 @@ def test_the_idle_prompt_holds_the_feet_and_asks_for_the_return_not_a_rhythm() -
def test_idle_is_pinned_and_its_whole_clip_is_the_loop() -> None:
assert "idle" in batch_mod.PIN_LAST_FRAME_STATES
- assert batch_mod.PINNED_LOOP_STATES == frozenset({"idle"})
- # an attack is pinned too, but cut as a one-shot with its own template
- assert "attack" not in batch_mod.PINNED_LOOP_STATES
+ assert batch_mod.PINNED_LOOP_STATES == frozenset({"idle", "attack"})
+ # an attack's whole clip is its loop too (one strike, stance to stance), with its own template
assert "Crisp, clean frames" in batch_mod.build_prompt("side", "attack", None)
+ assert "Crisp, clean frames" not in batch_mod.build_prompt("side", "idle", None)
# the other states keep the evenly paced loop
assert "evenly paced" in batch_mod.build_prompt("side", "walk", None)