Making a small 2D game usually means juggling several tools. You lay out the level in one place, tune physics and behaviors in code, build the HUD somewhere else, and playtest by hand. Each hand-off loses context, and "does it still work?" gets answered by clicking around.
Clockwork is a 2D game engine that runs in the browser and keeps all of that in one app. You build scenes, attach behaviors, write rules, design the HUD, play the game, and share it from the same window. Kane CLI then drives that same app in a real Chrome browser to prove the editor and the games work end to end.
We built Clockwork during the KaneCLI Online Hackathon. This post covers the engine itself and how Kane CLI tests it. A companion post covers the built-in AI agent and how it uses Kane to verify the games it builds.
Inside the engine
Scenes, layers and parallax
A Clockwork project holds one or more scenes. Each scene has a world size, a background and an ordered stack of layers. Every layer has its own opacity and its own parallax factors on X and Y, so a distant sky can scroll slower than the ground the player runs on.
Clockwork Meadows, the showcase starter, uses four layers: Sky, Mountains, Forest, and Meadow and actors. Its world is 18,400 × 1,200 pixels and holds 227 objects. Camera follow keeps the player in view across that width. Fixed-screen games shrink to fit instead, so the whole playfield stays visible in a smaller window.
Behaviors
Clockwork ships 27 composable behaviors, defined in src/engine/model/behavior-catalog.ts. You attach them to objects in the Inspector and tune their parameters, and every parameter shows its default with a Reset button. They include:
- Movement: platformer-controller, top-down-controller, rotate-thrust, flap, mover, snake.
- Enemies: patrol, follow, formation, stompable, melee.
- Game objects: collectible, hazard, checkpoint, exit-gate, spawner.
- Combat: health, shooter, projectile.
- Arcade: ball, paddle, ai-paddle.
- Timing and camera: timer, countdown, camera-follow.
A behavior is a small, focused unit. The Meadows player, Marlow, combines a platformer controller (speed 340 px/s, a 135 ms jump buffer, a tuned jump cut) with camera follow. A coin is just an object with collectible. You build new mechanics by combining behaviors.
Rules, variables and HUD widgets
Behaviors cover moment-to-moment play. Rules cover game logic. A rule pairs a list of conditions (overlap, input, timer, scene start, variable) with a list of actions (set, add to or toggle a variable, spawn a prefab, destroy, play a sound, show a message, change scene). That's enough to say "when the player overlaps a coin, add 1 to score and destroy the coin" without code. Variables hold game state such as score, lives or shards, and HUD widgets bind to them so the screen always shows the live value. Rules and variables live in the editor's Logic tab. Look, animation, audio and UI live in Presentation.
Prefabs, undo and redo
Prefabs let you define an object once and stamp out copies. Every edit goes through one command registry. The editor footer states the contract: "One completed gesture = one revision and one undo entry." Dragging an object, changing a field or applying a batch of changes therefore always undoes as a single step.
Starters
You can start a project from Blank, from one of three classic templates (Platformer, Top-down, Puzzle), from a written brief, or from one of 14 genre starters:
Space Shooter, Space Invaders, Asteroid Field, Ping Pong, Brick Breaker, Flappy Flyer, Platform Jumper, Clockwork Meadows, Meadow Sandbox, Endless Runner, Arena Survival, Falling Objects, Maze Escape and Snake.
Each starter is built from the same behaviors, rules and HUD widgets you use in your own projects, so you can open any of them and change how it works.
Clockwork Meadows is the largest. You run the meadow, stomp dragons, light checkpoints, collect sun shards and reach the summit camp. Press Play and the four layers scroll at their own rates behind the player.
Share and ship
When a game is ready, the Ship panel publishes it:
-
Share links. Clockwork freezes the current project into a read-only snapshot served at
/s/:snapshotId(src/routes.tsx). Anyone with the link plays that exact version, and later edits in the editor don't change it. You choose how long the link lives. -
Zip export. Clockwork packages the game and its assets as a standalone static build (
src/engine/io/build.ts) that you can host on any static web server. -
Project file. The whole project also exports as
.clockwork.json, which the New Project dialog can import.
Snapshots also matter for testing. AI Play and the agent's Kane checks run against a snapshot rather than the live editor, so the version under test can't change mid-run.
Kane CLI tests the engine end to end
Unit tests cover the engine's logic: pnpm test runs 176 tests across 27 files, and all 176 pass. Unit tests can't show that a person can open the app, build a game and play it. Kane CLI covers that.
Clockwork keeps a saved Kane test at .testmuai/tests/engine-template-e2e_test.md. It is a plain Markdown file with a short front-matter block (mode: testing, max_steps: 50, timeout: 480, target: chrome) and one step written in plain English. In that step Kane:
- Opens Clockwork and creates a project named "Engine E2E Platformer" from the Platform Jumper starter.
- Checks that the scene canvas and the Scene hierarchy are visible.
- Selects the "Jumper" row in the hierarchy and records its Object Y in the Inspector.
- Presses ArrowUp twice to nudge the object, then Control+Z twice, and checks that Object Y is back to the recorded value.
- Presses Play and checks for the game canvas and the CORES and LIVES HUD labels, with LIVES reading 3.
- Presses Space and checks that LIVES still reads 3.
- Presses R to restart and checks the HUD again, with LIVES at 3.
- Returns to the editor and checks that the project is still open with its canvas and hierarchy.
One flow covers project creation, the hierarchy, the Inspector, keyboard editing, undo, Play, the HUD, restart and the return to the editor.
Run it with one command:
pnpm kane:engine-e2e
scripts/kane/engine-e2e.mjs runs the saved test through kane-cli testmd run. It prints one compact JSON result and keeps the raw NDJSON stream, a result summary and the evidence pack under .testmuai/.
The first authored run passed in 286 s. A later run of the one-command variant, pnpm kane:engine-e2e:dev, started the app from cold, replayed the saved step and passed in 89 s. For this post we ran pnpm kane:engine-e2e again. It passed 1 of 1 steps, replayed, in 134 s (session c6bc88c1).
Because the test is a Markdown file in the repo, it is versioned with the code, can be reviewed in a pull request, and runs again with the same command.
Layout precision: Clockwork's HUD audit
Kane reads Clockwork's HUDs as page text and clicks their buttons, so those panels have to stay clear of each other. Clockwork has its own layout audit for this, separate from Kane: pnpm test:hud (scripts/kane/hud-overlap-check.mts).
The audit connects to Chrome over the DevTools protocol. It builds every template and starter, publishes each one as a snapshot, and opens it in three player modes: real-time play, manual Test Mode, and Test Mode with planned check steps. It opens each mode at two viewport sizes, 1280×800 and 1024×640. On every page it checks two things:
- Every button and input can be clicked. It hit-tests each control at its centre and at four inset points, and the element under each point must be the control itself.
- No two HUD panels overlap. This covers the AI and Test Mode readouts, control groups, the game's own HUD widgets, the "Made with Clockwork" badge and the PAUSED/Restart pill.
Our run printed:
108/108 layouts clean.
That is 18 starting points × 3 modes × 2 viewports. The audit also writes a full report to .data/hud-overlap/report.json.
Wrap-up
Clockwork puts a 2D game engine, its editor and its verification in one browser app. Its runtime, physics, 27 behaviors, rules, HUD widgets and Test Mode are built for that workflow. Kane CLI proves the main editor path in a real browser with a saved test you can rerun anytime. The companion post shows how Clockwork's built-in agent uses Kane to check the games it builds.
- Source code: https://github.com/tope-olajide/clockwork
- Demo video: https://youtu.be/ybe9e93r4SU





Top comments (1)
Verifying end to end in a real browser instead of trusting the agent's report is the part that makes this interesting. For a game engine the only honest test is a player touching the thing. How long does a full verify run take per change?