Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pocket-stack/pocketjs/llms.txt
Use this file to discover all available pages before exploring further.
@pocketjs/framework/lifecycle exposes component-scoped hooks into the PocketJS frame loop. Each hook registers a callback that is automatically cleaned up when the owning Solid owner (or Vue scope) disposes — onCleanup for Solid, onScopeDispose for Vue Vapor. Call these functions inside a component body or a reactive effect; calling them outside a reactive context will leave stale callbacks registered forever.
The frame loop contract: once per vblank/rAF tick the host calls globalThis.frame(buttons). The runtime runs frame hooks first (user callbacks via onFrame/onButtonPress), then input edge-detection and focus navigation, then the renderer’s end-of-frame sweep that destroys detached subtrees. This ordering means reactive state updates from button presses are applied before the sweep, so remove-then-reinsert within a single frame always works correctly.
onFrame
Registers a callback to run once per vblank tick. The callback receives the current raw BTN bitmask as its argument. Use onFrame for frame counters, per-frame animation drivers, HUD updates, or any logic that must execute on every tick.
Called once per host frame.
buttons is the full held-state bitmask using the BTN constants from @pocketjs/framework/input. The callback runs before the input edge-detection stage, so buttons reflects the raw held state for this tick — not a pressed edge.onCleanup internally.
Example — frame counter and per-frame HUD update:
onButtonPress
Registers an edge-triggered button handler. Fires once when the specified button transitions from up to down — not continuously while held. The callback is removed automatically when the component or effect is disposed.
The
BTN constant or bitmask to listen for. Combine multiple buttons with bitwise OR to fire when any of them is pressed (e.g. BTN.CROSS | BTN.TRIANGLE).Called on button-down.
pressed is the just-pressed bitmask subset of mask; buttons is the full held bitmask for this frame. Use buttons to detect modifier combos.Optional gate and block-override options. See
ButtonPressOptions below.ButtonPressOptions
Options that control when an onButtonPress handler fires.
| Field | Type | Default | Description |
|---|---|---|---|
allowWhenBlocked | boolean | false | When true, the handler fires even while a modal or system block is active (i.e. while pushButtonHandlerBlock depth is greater than zero). Normal app handlers should leave this false. |
active | boolean | (() => boolean) | true | Gate the handler. When false (or when the getter returns false), the callback is suppressed for that frame. Accepts a reactive getter — changes take effect on the next frame. |
pushButtonHandlerBlock
Pushes a global block that suppresses all onButtonPress handlers that do not opt in with allowWhenBlocked: true. Returns an unblock function; call it when the blocking condition ends. Modal uses this internally to capture input while open.
() => void — call this function to unblock. Calling it more than once is safe (subsequent calls are no-ops).
Example — custom blocking overlay:
createSpriteAnimation
Cycles through a list of image src keys on each host frame, returning a reactive accessor for the current frame key. Use this when you need a JS-driven frame sequence rather than a baked Sprite atlas — for example, mixing frames from different atlas sources or pausing at a specific frame reactively.
Ordered list of image
src keys (bare names from the pak, matching what you pass to <Image src="…">). Must not be empty — throws if frames.length === 0.Optional timing configuration.
Accessor<string> — a reactive getter for the current frame key. Pass it to <Image src={currentFrame()} />.
SpriteAnimationOptions
| Field | Type | Default | Description |
|---|---|---|---|
frameStep | number | 1 | Number of host frames each sprite frame remains visible. Minimum 1. A value of 2 halves the animation speed (30 fps at 60 Hz); 4 quarters it (15 fps). |
<Sprite> primitive — it plays directly from a baked atlas with zero per-frame JS. Use createSpriteAnimation only when you need reactive control over which frame is displayed or when blending frames from multiple pak entries.
Component lifecycle example
A complete example combiningonFrame, onButtonPress, and a cleanup-safe pattern:
onFrame and onButtonPress are cleaned up automatically when GameHUD unmounts — no manual teardown is required.