Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
useSpawn returns a function that appends new nodes to a container at runtime. Call the returned spawn function with any JSX expression to create and attach the node as a child of the target container. This is the recommended pattern for dynamically creating enemies, projectiles, particles, or any node that does not exist at scene-load time.
useSpawn
Signature
Parameters
A
NodeReference to the container node that will receive spawned children. Create this with useRefNode and attach it to a JSX node via the ref prop.Return value
(jsx: Tiny.Node) => void — a spawn function. Pass any JSX expression to it; the resulting node tree is rendered and added as a child of the container.
Example — spawner that creates enemies on click
Spawner.tsx
Example — spawning projectiles
Player.tsx
useSpawn captures the current hook context at the time the component function runs. This ensures that hooks used inside the spawned JSX component — such as useSignal or useEffect — are associated with the spawned node, not the parent. Always call spawn from event handlers or useMount, not during component setup.useMount
useMount runs a callback when the component’s root node starts, and runs it again when the node is destroyed. If the callback returns a cleanup function, that cleanup is invoked first — immediately before the second call on destroy. Use useMount for setup and teardown code that should not re-run when signals change.
Signature
Parameters
The function to run when the node starts. It can optionally return a cleanup function that is invoked before
fn is called again on node destroy.Return value
void
Example
AudioPlayer.tsx
useGame
useGame returns the GameControls object, giving a component direct access to the global game loop and scene manager.
Signature
Return value
| Property | Description |
|---|---|
play() | Resumes the game loop if it was paused. |
pause() | Pauses the game loop. |
changeScene(name) | Unloads the current scene and loads the named scene. Returns a promise that resolves when the transition is complete. |
preloadScene(name) | Loads the named scene in the background while the current scene remains active. Returns a promise that resolves to a setter function; call the setter to perform the instant scene swap. |
getSize() | Returns the canvas dimensions as a Vector2. |
Example
PauseMenu.tsx