Examples
Each example solves one common game task with complete scripts you can paste into a project: what it does, how to set the scene up in the editor, the code, what each part does, and changes to try. Every code block on these pages is compiled against the engine when the site is built.
Most of them come from the editor’s demo project (examples/demo_project, opened the first time
the editor starts): the space game and the forest platformer. If you haven’t written a script
yet, start with Your first game, then Scripts
in the manual.
Moving
Section titled “Moving”Move a character with input actionsTop-down movement with easing, walls and a dash, on keys and gamepads.
A platformer characterRunning, jumping, coyote time, a jump buffer, short hops, one-way platforms.
Camera follow, shake and hitstopA look-ahead camera inside the level's bounds, zoom, and hits you can feel.
Gameplay
Section titled “Gameplay”Collect coinsAreas, a global count, a sound, a sparkle, a label.
Enemies that patrol and get hurtPatrols, stomps, damage, knockback, a red flash, fading out.
Spawn bullets and effectsComponents made from code that remove themselves.
Read LDtk entities and fieldsFields, entity references, the IntGrid, entities made by code.
The game around it
Section titled “The game around it”Save and load progressA global script, checkpoints, settings, Save_Game and Load_Game.
A HUD with a health bar and scoreUI nodes, or a global that draws over every scene.
Sounds, music and busesFootsteps, crossfading music, layers, bus volumes.
Scene changes, transitions and a pause menuDoors with wipes and fades, a menu over the level.
Polish
Section titled “Polish”Animations from a state machineA StateMachine node picks the animation from what the script reports.
Talk to a characterA DialogueBox, choices, variables and commands that run code.
Juice with tweensPops, squashes, pulses, floating numbers and sliding doors.
