As a game grows, keeping all logic inline with JSX components becomes difficult to maintain.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/fraxel/llms.txt
Use this file to discover all available pages before exploring further.
FraxelScript provides a class-based alternative: write game logic — health systems, state machines, AI routines — in a plain TypeScript class that extends FraxelScript, then attach it to any JSX node via the script prop. The script receives a typed reference to its host node and can subscribe to the node’s lifecycle events through setup() and connect().
Creating a Script
ExtendFraxelScript<PrimaryNode.X> where X is the PrimaryNode enum value matching the node type the script will be attached to. Override setup() to register event listeners and initialise state.
PrimaryNode.Transform) tells the compiler which node instance this.me returns and which event names connect() accepts — both are fully type-checked.
Attaching to a Node
Pass a script instance to thescript prop on any JSX node. The node constructor calls script.init(node) and then script.setup() automatically.
Accessing Scripts
Use theuseScript hook to retrieve the script from a node reference. It returns a SignalGetter<T> — call it to get the current script instance.
useScript returns a reactive getter, so you can use it inside useComputed or useEffect and it will re-run whenever the referenced node changes.
Script API
me
The me property returns the node instance the script is attached to. Its type is NodeInstances[T] — fully typed based on the generic parameter you supplied.
me before init() has been called throws a NodeNotInitializedError. In practice setup() is called immediately after init(), so me is always available inside setup() and any event callbacks registered there.
connect(eventName, callback)
connect is a type-safe wrapper around the node’s event system. The first argument is an event name string; the compiler infers the correct callback signature from the node type.
Collider’s colliderEntered), those event names are also accepted by connect() with correct callback types.
setup()
setup() is an abstract method — you must override it. It is called once, right after the script is bound to its node, before the first frame runs. It is the correct place to register event listeners and set up any long-lived subscriptions.
Game.destroy()
CallGame.destroy() to fully tear down the engine: stops the animation loop, releases the wake lock, removes all window event listeners, and destroys the current scene and all its nodes.
Game.destroy() also calls Game.input.destroy() internally, ensuring all keyboard and pointer listeners are cleaned up. Omitting this call in single-page applications causes input listeners to accumulate across navigations.
For the full node event reference, see API: Nodes (2D) and API: Nodes (Utility). For reactive hooks used alongside scripts, see API: Hooks (Core).