Hopkit / Reference
Working with game systems
Use the framework workshop to integrate controls, collision, animation and saved game state.
The framework workshop contains five playable experiments and one
portable source download. Install it outside the Hopkit checkout, change a rule
or an asset, and run its check and export scripts. Its src/recipes directory
contains editable mechanics, with integration instructions and MIT notices.
Time and scene ownership
Use createGame for a browser game. It owns rendering, input commits and cleanup.
Register a scene factory when you need restart. game.restart() reruns that factory;
it does not invent a reset for an arbitrary external model. Keep resettable state
inside the factory or reset it explicitly. Canvas buttons remain usable while paused.
The time experiment runs two independent headless simulations from one browser owner. Try pausing or disposing one, replacing a scene, cancelling a wait and restarting repeatedly. The other simulation retains its state. See the runtime contract.
Controls and gestures
scene.input.rebind(profile) validates a complete replacement before switching
keyboard/controller bindings. scene.input.profile returns a detached snapshot.
Use loadControlProfile and saveControlProfile with a storage implementation;
report storage failures without throwing away working controls.
scene.input.createSource() keeps independent controls from releasing each other.
virtualStick and gestures belong to the scene. Convert client positions to logical
coordinates, restrict the accepted region, and render their state in canvas.
Gestures provide independent drag, swipe and slicing segments for each pointer.
Demand games can opt into gamepadPolling: "continuous". This keeps their existing
frame owner sampling controllers while visible and unpaused. Unchanged values do
not advance a demand simulation. Use continuous game mode for movement while held.
Try the control room and read the
input contract.
Movement and collision
Copy the movement recipe into your game and call it from the existing update. The platform controller supports jump buffering, coyote time, variable jump height, one-way platforms, moving supports and top-only slopes up to 45 degrees. The slope contract uses the character’s center foot. A blocked moving support reports a result; your game decides whether that means crushing, stopping or another rule.
Circle sweeps and bounded bounce handle fast balls against static boxes, circles and segments. Collision layers/masks, a spatial hash and contact history remain ordinary source utilities. Initial penetration and exhausted impact budgets have explicit results. They are not a general rigid-body physics engine.
Play the platform course and ricochet arena. The movement contract documents coordinates, ordering, shapes and time limits.
Assets, animation and sound
Image definitions accept Aseprite or TexturePacker atlas metadata with an explicit
image URL. Loaded images expose named frames and clips. AnimationController
advances from your update and supports named playback, interruption and finite
sequences. Frame metadata retains the documented trim, pivot and rotation behavior.
scene.assets.bundle(definitions) exposes loading, ready, error and released states.
Show its progress, handle ready rejection and offer retry(). Scene exit releases
the bundle and prevents late attachment. Audio has separate music/effects controls
and crossfadeMusic for decoded tracks.
The editable feedback recipe supplies squash/stretch, trails, hit-stop and screen transitions. Advance feedback normally and pass its returned time only to world rules. Menus, input and audio keep their normal owner during hit-stop. Reduced motion changes presentation without changing those rules.
Try motion and sound, including failed-load retry and restart. The asset contract explains lifetime, callbacks, imported formats and audio limits.
Save, undo and replay
SnapshotCodec validates and migrates domain data. SaveSlots namespaces independent
slots and returns explicit success/failure results. Replace live state only after a
successful validation and storage operation. Guard asynchronous imports against
scene exit and newer user actions; the workshop shows that complete workflow.
The gameplay recipe includes seeded randomness, reversible moves, legal grid turns and round progression. Replay data records a model/version, initial state, seed, step size, accepted inputs and external events. Playback reproduces that model’s rules; it is not a whole-game or cross-platform determinism promise.
Seed Trail demonstrates save/resume, two slots, import/export, undo/redo, replay and win/loss/retry. Read the gameplay contract before adapting its schema and rules.