Events allow trigger functions to react to in-game occurrences such as touch input, collisions, player death, and positional thresholds. The central pattern isDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/g-js-api/G.js/llms.txt
Use this file to discover all available pages before exploring further.
on(someEvent(), callback) — on wires the event to a group or trigger function, and the event factory configures what to listen for.
on
Registers a trigger function or group to be called whenever the given event fires.An event object returned by one of the event factory functions below.
A trigger function or group to call when the event fires.
touch
Listens for a screen-touch event. Returns aGJsEvent to be passed to on.
When
true, only listens to dual-side touch input.GJsEvent.
touch_end
Listens for when the screen stops being touched.When
true, only listens to dual-side touch release.GJsEvent.
collision
Fires when two collision blocks begin overlapping. Useblock() to create block IDs, and pass P1/P2 to substitute the player for block a.
First collision block.
Second collision block.
Use Player 1 as block
a.Use Player 2 as block
a.GJsEvent.
collision_exit
Fires when two collision blocks stop overlapping.First collision block.
Second collision block.
Use Player 1 as block
a.Use Player 2 as block
a.GJsEvent.
death
Fires when the player dies.GJsEvent.
count
Fires when a pickup item or counter reaches a specific value. Settingmulti to true allows the event to fire repeatedly each time the value is hit.
The item ID to watch (typically
counter.item).The value that triggers the event.
When
true, the event can fire more than once.GJsEvent.
x_position
Fires when the player’s X position reaches the specified coordinate.The X coordinate at which the event triggers.
GJsEvent.
frame
Returns aGJsEvent that fires on every game tick (1/240 s). Use with on to run a trigger function every tick.
GJsEvent.
render_frame
Returns aGJsEvent that fires on every render frame. Render frames are variable and depend on the player’s display frame rate setting.
GJsEvent.
event
Low-level access to the GD Event trigger. Lets you listen to named events with optional extra IDs for more granular control.The event name or event object to listen to.
Extra ID 1 for additional filtering.
Extra ID 2 for additional filtering.
GJsEvent.
gamescene
Returns aGamescene object that exposes the four player-input buttons as event sources, plus a hidden_group for internal use. This is the recommended way to handle jump/input events in dual-player levels.
Gamescene.
Gamescene Interface
Event fired when Player 1 presses the jump button (button A).
Event fired when Player 2 presses the jump button (button B).
Event fired when Player 1 releases button A.
Event fired when Player 2 releases button B.
Internal group used by the gamescene system.