G.js exposes a clean event system that maps directly onto Geometry Dash’s trigger layer. Every event is aDocumentation 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.
GJsEvent value that you pass to on(), which wires up a GD trigger so your callback group fires automatically whenever the event fires during gameplay. This means you never have to manually manage touch triggers, collision triggers, or on-death triggers — just describe what you want to react to and G.js emits the correct objects for you.
on(event, callback)
on is the entry point for the entire event system. Call it at the top level of your script (or inside a trigger function) to register a listener:
Any value returned by one of the event constructor functions below.
A trigger function (from
trigger_function(...)) or a raw group to call when the event fires.Touch Events
touch(dual_side?)
Fires when the player touches the screen.
When
true, only listens to input on the dual side of the screen.touch_end(dual_side?)
Fires when the player releases the screen.
When
true, only listens on the dual side.Collision Events
collision(a, b, P1?, P2?)
Fires when two collision blocks start overlapping.
First collision block.
Second collision block.
When
true, Player 1 acts as block a.When
true, Player 2 acts as block a.collision_exit(a, b, P1?, P2?)
Fires when the two blocks stop overlapping. Takes the same parameters as collision.
Player Events
death()
Fires when the player dies.
x_position(position)
Fires once when the player’s X coordinate reaches a specific position.
The X coordinate (in GD units) that triggers the event.
Item / Count Events
count(it, hits, multi?)
Fires when a counter (item) reaches a specific value.
The item ID to watch. Retrieve it from
your_counter.item.The number the item must reach to fire the event.
When
true, the event fires every time the value hits the target (not just once).Frame Events
G.js distinguishes between ticks (fixed 1/240 s intervals, independent of frame rate) and render frames (variable, depends on the player’s FPS setting).frame()
Fires every game tick — exactly once every 1/240 second, regardless of frame rate. Use this for deterministic, physics-accurate logic.
render_frame()
Fires every rendered frame. The interval varies with the player’s FPS settings. Use this for visual-only effects where exact timing doesn’t matter.
Prefer
frame() for gameplay logic (counters, movement, collision responses) and render_frame() for purely cosmetic effects. The control-flow equivalents frame_loop() and render_frame_loop() provide the same distinction with an easier stop mechanism — see the Control Flow guide.Custom Event Trigger
event(ev, extra_id?, extra_id2?)
Wraps GD’s Event trigger, which lets you fire named events from elsewhere in the level and listen to them here.
The event identifier or event object to listen to.
Optional extra ID 1 for the Event trigger.
Optional extra ID 2 for the Event trigger.
Gamescene Input Controls
gamescene() returns a Gamescene object that abstracts the in-game button inputs, making it easy to bind logic to the jump/action buttons without dealing with raw touch coordinates.
Gamescene interface:
| Property / Method | Type | Description |
|---|---|---|
button_a() | GJsEvent | Button A (jump) pressed. |
button_b() | GJsEvent | Button B pressed. |
button_a_end() | GJsEvent | Button A released. |
button_b_end() | GJsEvent | Button B released. |
hidden_group | $group | A group that is hidden by the gamescene context. |
Examples
Touch to Spawn a Group
Collision-based Logic
X-Position Sequence Trigger
Frame Loop vs. Frame Event
Control Flow
frame_loop, for_loop, and sequence for structured timing.Counters
Track game state with item-backed counters.
Events API
Full API reference for all event functions.
Groups & Colors
How groups, colors, and blocks map to GD IDs.