# Trisgine Wiki (full text)
Source: https://wiki.trisgine.com
---
# What is Trisgine?
URL: https://wiki.trisgine.com/start/what-is-trisgine/
A data-oriented game engine you can use straight from your browser, by hand or together with an AI agent.
Trisgine is a game engine built by Trisgram. Its core is written in C++ and runs on an
entity-component-system (ECS) store called DoDB. The same engine is compiled to
WebAssembly + WebGPU, so the **full editor runs in a browser tab** at
[editor.trisgine.com](https://editor.trisgine.com). You don't install anything or compile anything, and
you need no C++ to make things with it.
This wiki covers two ways of working with that web editor:
| | You | What you'll use |
|---|---|---|
| **By hand** | click, drag, paint and wire nodes | Hierarchy, Inspector, Scene view, Pixel Art, Tilemap, Script Editor |
| **With AI** | describe what you want; an agent builds or edits it | the `window.tgDebug` automation API, text asset formats, AI sprite generation |
Both produce the same files, so you can switch between them freely.
## What you can build today
- **3D scenes** from primitives (cube, sphere, cylinder, capsule, wedge, quad), imported
meshes (`.obj`, `.fbx`, `.gltf`/`.glb`), lights, a sky and post-processing.
- **First-person exploration games**: the built-in `FreeLookCamera` gives you WASD + mouse-look
movement with no code at all.
- **Interactive props** with *visual scripts*: things that react when the player comes close,
move, open, hop, disappear.
- **2D worlds**: pixel-art sprites, flipbook animation, tilemaps, 2D physics (boxes, circles,
sensors and joints), and a 2D camera.
- **Menus and HUDs** with the UI system (canvases, panels, text, buttons, sliders and more).
- **Sound**: positional audio sources, reverb zones, and impact sounds for 2D physics.
> [!NOTE]
> Trisgine is young and moves fast. Some features (for example spawning or removing entities
> from a script) are not there yet. Each page says
> plainly where a limit is, so you don't lose an afternoon looking for a button that
> doesn't exist. The [glossary](/reference/glossary/) explains the vocabulary.
## Where to go next
1. [Open the editor](/start/open-the-editor/) and check that your browser is supported.
2. Spend [your first five minutes](/start/first-five-minutes/) finding your way around.
3. Build [a 2D RPG](/rpg2d/overview/) from start to finish, using only the web editor.
4. Let an AI do the clicking: [Working with AI](/ai/overview/).
---
# Open the editor
URL: https://wiki.trisgine.com/start/open-the-editor/
Browser requirements, the two editor addresses, and what happens on first load.
## Requirements
The editor renders with **WebGPU**. You need a desktop browser that supports it:
- **Chrome or Edge 113+**. This is the recommended choice and the one the team tests on.
- **Safari 18+** on macOS.
If your browser has no WebGPU, the loading screen stops with *"WebGPU is not available in this
browser."* Update the browser, or switch to Chrome/Edge.
A mouse with a right button and a scroll wheel makes the 3D views much easier to use. A
discrete GPU helps but is not required.
## The address
The editor lives at [editor.trisgine.com](https://editor.trisgine.com). Your projects are stored in
your browser on that address (see [Saving & storage](/editor/saving-and-storage/)).
## First load
1. The page downloads the engine. The first visit takes a few seconds; after that the files
are cached, and the editor can even start offline.
2. The editor opens with its default layout (see [the interface](/editor/interface/)).
3. Everything you create or import is stored **in your browser**, in the private
[Origin Private File System](/editor/saving-and-storage/). It is still there the next
time you open the same browser on the same machine.
## Checking the version
**Help > About Trisgine** shows the version and the exact build. In the browser's developer
console, `tgBuild` gives the same build hash. Mention it whenever you report a bug.
> [!NOTE]
> The editor is updated often, and this wiki sometimes describes a feature a few days before
> it reaches you. If a menu item from this wiki is missing, reload the page to pick up the
> latest build.
---
# Your first five minutes
URL: https://wiki.trisgine.com/start/first-five-minutes/
Create an object, move it, colour it, play, and save, all in the browser.
This is a quick hands-on tour. You'll touch the five panels you use all the time.
## 1. Make something
Right-click an empty area of the **Hierarchy** (the list on the left) and choose
**Add Mesh > Cube**. A cube appears in the **Scene** view and is selected.
## 2. Look around
Inside the **Scene** view:
- hold the **right mouse button** and drag to look around;
- while holding it, press W A S D to fly, and Q / E to go down or up;
- press F to frame the selected object.
## 3. Move it
Press W for the move gizmo and drag the arrows. E rotates and
R scales. Hold Ctrl while dragging to snap to the grid.
You can also type exact numbers in the **Inspector** (right side) under **Transform**.
## 4. Give it a colour
In the Inspector, find **Material > Surface > Base Color**, click the swatch and pick a
colour. Base Color multiplies the texture, so with a white texture you get exactly the
colour you picked.
## 5. Press Play
Press the **▶ Play** button at the top. The **Simulation** panel now runs the game from
the player camera's point of view. Press the same button (now **■ Stop**) to stop: the
world goes back to how you authored it. **Nothing you change during play is kept.**
## 6. Save
Press Ctrl+S while the Scene view or the Hierarchy has focus, or choose
**File > Save Scene**. An orange **Unsaved** pill at the top tells you when there is work that
hasn't been saved yet. Hover over it to see exactly what.
> [!TIP]
> Lost a panel, or rearranged things into a mess? The **Layout** button at the top right,
> then **Reset to Default**, puts every panel back where it started.
Next: [a tour of the whole interface](/editor/interface/).
---
# The interface
URL: https://wiki.trisgine.com/editor/interface/
Every panel, menu and toolbar button in the web editor, and where to find it.

## Default layout
| Area | Panels |
|---|---|
| Left | **Hierarchy**: every entity in the open scene |
| Centre | **Scene** (where you edit) and **Simulation** (the game view), side by side |
| Right, tabbed | **Inspector**, **Metrics**, **Systems** |
| Bottom, tabbed | **Project**, **Console**, **Profiler**, **Render Debug**, **Localization** |
Every panel is dockable. Drag a tab by its title to move it, or drop it on the edge of another
panel to split. Right-click a panel's title bar (or double-click it) to make it **fullscreen**,
and press Esc to return. **Layout > Reset to Default** restores the original arrangement.
## The panels you use every day
- **Hierarchy**: lists the entities in the scene. Click to select, drag one onto another to make
it a child, use the eye icon to hide it, and right-click for the
[create menu](/editor/hierarchy-and-inspector/#creating-entities). The first row,
**Settings**, holds scene-wide settings (graphics, post-process, audio, sky, fog, water…).
- **Scene**: the editing viewport, with gizmos, a grid, and a floating tool palette. See
[the Scene view](/editor/scene-view/).
- **Simulation**: what the player sees, from the player camera (3D) or the first active 2D
camera. This is where the game runs when you press Play.
- **Inspector**: the components of the selected entity, or the details of the selected asset.
The **Add Component** button is at the bottom.
- **Project**: your files: scenes, scripts, textures, sounds and so on. See
[the Project browser](/editor/project-browser/).
- **Console**: engine messages, with filters for each severity. Click the message in the
status bar (bottom-left) to jump here.
## Menu bar
| Menu | Items |
|---|---|
| **File** | New Scene · Open Scene ▸ · Reload Current Scene · Save Scene (Ctrl+S) |
| **Edit** | Undo / Redo (each shows what it will undo) · Duplicate (Ctrl+D) · Delete (Del) |
| **Assets** | Import… · Reload Shaders |
| **Windows** | Console · Profiler · Shader Editor · Script Editor · Pixel Art · Tilemap · Particle Editor · Render Debug · Projects · Pop Out ▸ · DoDB Inspector · Physics · Localization · Layout ▸ Reset to Default |
| **Help** | Keyboard Shortcuts · Getting Started · Open Sample Scene ▸ · About Trisgine |
**Windows > Pop Out ▸** moves a panel into its own browser window, which is handy with two
monitors. If nothing happens, your browser blocked the pop-up; allow pop-ups for the editor.
## Toolbar
The strip under the menu, from left to right:
- **▶ Play / ■ Stop**: run the game; Stop restores the world exactly as you authored it.
- **❚❚ Pause / Resume**, and **Step** to advance one frame while paused.
- **Physics freeze** and **physics substep**: freeze only the physics (everything else keeps
running), and step it one substep at a time to inspect a collision.
- **Sync** status: the collaboration connection (blue *Signed out* until you
[sign in](/editor/account-and-sync/)).
- **Unsaved** (orange): there is work a reload would lose. Hover to see what.
- **Layout**: Reset to Default.
The **Account** button at the very top-right of the page is not part of the editor canvas.
It opens the sign-in form.
## Status bar
The bottom line shows the latest console message on the left, and the open scene's name
(with `*` when it has unsaved changes) and the frame rate on the right.
## The specialist editors
These open from the **Windows** menu, or by double-clicking a matching file in the Project panel:
| Window | Edits | Page |
|---|---|---|
| Pixel Art | `.png` / `.tgpx` sprites, with layers, frames and AI generation | [Pixel Art editor](/2d/pixel-art-editor/) |
| Tilemap | `.tgtilemap` grids | [Tilemaps](/2d/tilemaps/) |
| Script Editor | `.tgscript` visual scripts | [Visual scripting](/logic/visual-scripting/) |
| Shader Editor | `.tgshader` node-based materials | not covered in this wiki yet |
| Particle Editor | `.tgparticle` effects | not covered in this wiki yet |
| Physics | a live table of every collider and body | [2D physics](/2d/physics-2d/) |
| DoDB Inspector | the raw ECS tables, and the system dependency graph | [Glossary](/reference/glossary/) |
| Profiler | frame timings; record and compare captures | not covered in this wiki yet |
---
# The Scene view
URL: https://wiki.trisgine.com/editor/scene-view/
Navigating in 3D and 2D, the gizmo tools, snapping, and the view options.
The **Scene** panel is where you place and arrange things. It never runs gameplay; that is
what the **Simulation** panel and the Play button are for.
## Navigating in 3D
| Action | Input |
|---|---|
| Look around | hold Right mouse and drag |
| Fly | while holding right mouse: W A S D or the arrow keys |
| Down / up | while holding right mouse: Q / E |
| Faster / slower | while holding right mouse: Shift (2×) / Ctrl (½×) |
| Change fly speed | while holding right mouse: mouse wheel |
| Pan | drag with the Middle mouse button |
| Move forward / back | mouse wheel |
| Frame the selection | F |
## Navigating in 2D
Toggle **2D** in the floating toolbar. Then drag with the right or middle mouse button to
pan, and use the wheel to zoom.
## Tools
The floating palette at the top-left of the Scene view, and its shortcuts:
| Tool | Key | Does |
|---|---|---|
| Hand / view | Q | navigate only |
| Move | W | drag arrows or planes |
| Rotate | E | drag rings |
| Scale | R | drag handles |
| Universal | T | move, rotate and scale in one gizmo |
The remaining palette buttons:
- **Pivot**: switch the gizmo between local and global axes.
- **Grid**: show or hide the grid.
- **Snapping** popup: gizmo snap on/off and step, and face-drag snap and step. Holding
Ctrl while dragging snaps temporarily.
- **2D**: switch the view to 2D.
- **Persp / Ortho**: perspective or orthographic (3D only).
- **Camera settings**: exact position, pitch/yaw and fly speed.
- **Debug view**: physics overlays (static / dynamic / kinematic colours).
- **Draw mode**: Shaded, Overdraw, Shadow cascades, or Depth.
- **Controls** (the **?** button): lists all of the above.
## Placing things
- Right-click inside the Scene view, without dragging, to open the **create menu**. The new
entity spawns where you clicked.
- Drag a mesh, tilemap or particle asset from the Project panel straight into the view.
- Click an object to select it; its outline highlights and the Inspector shows it.
> [!TIP]
> Coordinates are **left-handed**: +X is right, +Y is up, and +Z points *into* the screen
> (forward). Rotations are in degrees.
---
# Hierarchy & Inspector
URL: https://wiki.trisgine.com/editor/hierarchy-and-inspector/
Creating entities, parenting, adding components and editing values.
## Entities
An **entity** is one "thing" in your scene: a cube, a light, the player camera, a sprite.
Unlike in many engines, an entity has no script object behind it. It is just a row of data
(position, mesh, material…), and *systems* process those rows every frame. In
practice that means you build behaviour by **adding components** and **listing systems**, not
by writing classes.
## Creating entities
Right-click empty space in the Hierarchy, or right-click in the Scene view:
| Item | Creates |
|---|---|
| **Create Empty** | an entity with just a transform |
| **Add Mesh ▸** | Cube, Sphere, Cylinder, Capsule, Wedge or Quad, with a default material |
| **2D Sprite** | a sprite (needs a 2D camera to be seen in Simulation) |
| **Audio Source** | a silent emitter; pick a clip in the Inspector |
| **Light ▸** | Point Light, or Directional Light (one per scene) |
| **Camera** | the player camera (one per scene) |
| **Particle System ▸** | one of the catalogued effects |
| **UI ▸** | Canvas (Screen), Canvas (World), then Panel, Button, Text, Image, Toggle, Slider, Scroll View, Dropdown |
Right-click an *existing* entity for **Rename** (F2), **Duplicate**
(Ctrl+D), **Delete** (Del) and **CSG ▸**: combine primitives
with *Make Subtract* / *Make Intersect* and bake the result with *Apply*.
> [!NOTE]
> Older editor builds only offer Create Empty, Add Mesh, 2D Sprite, Audio Source and UI. If
> you need a camera or light there, start from an existing scene or
> [import a scene file](/editor/project-browser/#importing-files).
## Parenting
Drag one Hierarchy row onto another to make it a child; it then moves with its parent. Drag
it onto empty space to unparent it. (Parenting works for 3D objects; 2D sprites don't
compose parent transforms yet.)
## The Inspector
Select an entity and the Inspector shows:
- a header with an **active** checkbox and the **name**;
- one collapsible **section per component**: Transform, Velocity, Angular Velocity, Mesh,
Material, Light, Camera, Script, Audio Source, Tilemap, Particle System, the UI sections and so on;
- a **⋮** menu on each section, with **Remove Component**;
- the **Add Component** button at the very bottom. Scroll down if you can't see it.
Values are edited in place. Drag a number field sideways to scrub it, or double-click to type.
### The Material section
- **Shader**: the material's shader. *AlbedoTexture* is the standard lit, textured one.
- **Main Maps > Albedo**: click the slot to pick a texture, for example one you painted in
[Pixel Art](/2d/pixel-art-editor/).
- **Surface > Base Color**: multiplies the albedo. With a white texture you get exactly this colour.
### The Script section
Every movable mesh has a **Script** slot that reads *(none)*. Click it and pick a
`.tgscript` file to attach it, or pick *(none)* to detach it. See
[Visual scripting](/logic/visual-scripting/).
### Add Component
The popup lists what can be attached to *this* entity, sorted A–Z. What can't be attached is
folded into **N unavailable**; hover a row there to see why. Common entries:
| Component | Use it for |
|---|---|
| Position / Rotation / Velocity / Angular Velocity | transforms and simple motion |
| **Script** | attach a [visual script](/logic/visual-scripting/) (when the entity has no slot yet) |
| Z-Order, Tint | 2D draw order and colour |
| **2D Camera** | turns an entity into an orthographic camera |
| **Tilemap** | draws a `.tgtilemap` at this entity's position |
| **CSG Brush** | primitives only: makes it add or cut geometry |
Lights, cameras, particle systems, sprites and canvases are not in Add Component. Create them
from the right-click menu instead.
## The Settings row
Select **Settings** at the top of the Hierarchy to edit scene-wide options: Graphics,
Post-process, Audio, Skybox, Water, Sky (day/night), Fog and Voxel Terrain. Remove a section
with its header ✕, or bring one back with **+ Add setting**.
---
# Project browser & importing
URL: https://wiki.trisgine.com/editor/project-browser/
Finding, creating and importing assets, and how assets are identified.
The **Project** panel (bottom dock) shows the files of your project, starting at `Assets/`.
## Getting around
- **◀ ▶ ▲** go back, forward and up a folder. The breadcrumbs (`Assets / Scenes`) are clickable.
- **Search…** filters the current view, and the dropdowns filter by type and sort the list.
- **Double-click** a file to open it in its editor: a scene loads, a `.tgscript` opens in the
Script Editor, a texture opens in Pixel Art, a `.tgtilemap` opens in Tilemap.
- A single click selects the asset, and the Inspector then shows its details: an image preview,
a mesh preview, an audio player with waveform, and so on.
## Creating assets
Right-click empty space in the panel, then **Create ▸**:
| Item | Makes |
|---|---|
| Script | `.tgscript` visual script |
| Shader Graph | `.tgshader` node material |
| Particle System | `.tgparticle` effect |
| Scene | `.tgscene` (empty) |
| Tilemap | `.tgtilemap` |
| Pixel Art | `.tgpx` layered sprite |
| Markdown | `.md` note, shown in the Inspector |
Right-click a file for **Open**, **Duplicate**, **Copy UUID**, **Open in Pixel Art** and
**Open in Tilemap**.
> [!WARNING]
> In the web editor, **Rename**, **Delete** and **Create > Folder** are greyed out. The browser
> file store can't rename or remove files yet. Choose your names when you create things, and
> use folders the editor makes for you (for example, the Script Editor's **New** creates
> `Assets/Scripts/`).
## Importing files
There are three ways to bring files from your computer into the project:
1. **Assets > Import…**: opens your system's file picker. You can select several files at once.
2. Right-click in the Project panel, then **Import…**.
3. **Drag files from your desktop and drop them anywhere** on the editor page.
Imported files land in **the folder the Project panel is showing**, or in `Assets/` if none
is open. Once imported, the asset is selected.
| Kind | Extensions |
|---|---|
| Images | `.png`, `.jpg` |
| Meshes | `.obj`, `.fbx`, `.gltf`, `.glb` |
| Audio | `.wav`, `.ogg`, `.mp3`, `.flac` |
| Engine text formats | `.tgscene`, `.tgscript`, `.tgtilemap`, `.tgpx`, `.uidoc` |
| Sidecars | `.mt` (only together with the asset it describes) |
Limits: 64 MB per file, and folders are refused (select the files inside instead).
> [!NOTE]
> Import arrived in mid-October 2026. If **Assets > Import…** is missing, your editor build
> is older. See [Open the editor](/start/open-the-editor/#checking-the-version).
## UUIDs and `.mt` sidecars
Scenes refer to textures, meshes and sounds by a 16-digit **UUID**, not by file name. Each
asset's UUID lives in a small sidecar file next to it, for example `grass.png.mt`:
```text
uuid:7A11C0DE00000001
```
If you import an asset **together with its `.mt`**, the editor keeps that UUID. That is how a
scene file someone sends you can find "its" textures. Without a sidecar, the editor makes up a
fresh UUID. To find an asset's UUID, right-click it and choose **Copy UUID**.
## Missing materials after an import?
Images decode in the background. If you open a scene the moment its textures finish
importing, some surfaces can show up white. **File > Reload Current Scene** fixes it.
---
# Play mode
URL: https://wiki.trisgine.com/editor/play-mode/
Running your game inside the editor, controlling the player, and what Stop does.
## Play, Pause, Step, Stop
| Button | Does |
|---|---|
| **▶ Play** | starts the simulation. The update systems run, scripts run, physics runs. |
| **❚❚ Pause** | freezes time; the Simulation view stays live. |
| **Step** | while paused: advances exactly one frame |
| **■ Stop** | ends play and **restores the world as you authored it** |
Anything that moves, disappears or changes during play is put back when you stop. Make your
real edits while stopped.
## Controlling the player (first-person)
A scene whose `input:` list contains **FreeLookCamera** has a playable first-person camera:
the entity tagged `PlayerTag` + `PlayerInputTag` with a perspective camera.
> [!IMPORTANT]
> The player only listens while **your mouse is over the Simulation panel**. Move the mouse
> into it first. The cursor hides and moving the mouse turns the view.
> [!WARNING]
> If the mouse leaves the Simulation panel while you are still holding a movement key, the
> player can keep drifting in that direction. Move the mouse back over the panel and tap the
> key again to stop it (a known issue).
| Input | Action |
|---|---|
| W A S D or arrows | walk |
| Q / E | down / up |
| Shift | 5× speed |
| Ctrl | half speed |
| mouse | look |
| Esc | release the mouse cursor |
The camera **flies**: there is no gravity or collision for it, so you can walk through walls
and off the edge of the map. Design around that (see the [3D RPG tutorial](/rpg/overview/)).
## Fullscreen play
Right-click the **Simulation** panel's title and choose **Run in fullscreen**, which also
presses Play. Press Esc to come back.
## Watching what runs
- **Systems** panel (right dock): each scheduled system, grouped by phase, with its cost in
microseconds. Untick one to switch it off while you experiment.
- **Metrics**: frame rate, draw calls, triangles, GPU memory.
- **Console**: script errors and warnings show up here.
## Sharing a game
The web editor can't publish or export a playable build yet. Your project lives in your
browser's storage. To show someone your game, share the files (scene, scripts, textures,
plus their `.mt` sidecars) so they can [import](/editor/project-browser/#importing-files) them,
or work together live with [sync](/editor/account-and-sync/).
---
# Saving & storage
URL: https://wiki.trisgine.com/editor/saving-and-storage/
Where your work lives in the browser, what "Unsaved" means, and how not to lose things.
## Where files go
The web editor has no access to your disk. Everything you create, import or save goes into
your browser's **Origin Private File System (OPFS)**. That is a private, per-site storage area,
and it survives reloads and restarts.
- It is **per browser and per machine**. Chrome on your laptop and Chrome on your desktop
are two separate projects.
- Private/incognito windows throw it away when you close them.
- Clearing "site data" for the editor deletes your project.
## Saving
- **Scenes**: Ctrl+S (with the Scene view or Hierarchy focused) or
**File > Save Scene**. Saving also writes any UI canvases (`.uidoc`) in the scene.
- **Scripts, pixel art, tilemaps**: each editor has its own **Save** button (and
Ctrl+S while it is focused). Pixel Art also autosaves a recovery copy.
If a save fails, a **Scene not saved** dialog tells you why. One possible reason: the browser
refused to store the file.
## The Unsaved pill
The orange **Unsaved** pill in the toolbar appears whenever a reload would lose something. Hover
over it to see a list such as *"the open scene has unsaved edits"* or *"a save is still being
written to durable storage"*. If you try to close or reload the tab with unsaved work, the
browser asks you to confirm.
When you switch scenes with unsaved edits, the editor asks: **Save and switch**,
**Discard and switch**, or **Cancel**.
## Backups
The editor can't export a project as a zip. Until it can:
- keep the **source files** of your assets (images, sounds, models) on your own disk, and
- for scenes and scripts, copy their text out. In the Script Editor, switch to the **Text**
tab, select all and copy. AI agents can read files with the [`tgDebug` API](/ai/tgdebug-api/).
> [!CAUTION]
> Browsers may evict site storage when the disk runs low. Treat the web editor as a
> workspace, not as the only copy of something you care about.
---
# Account & live sync
URL: https://wiki.trisgine.com/editor/account-and-sync/
Signing in from the web editor and connecting to the collaboration server.
## Signing in
Click **Account** at the top-right of the page. It is a normal web form that sits over the
editor, not an editor panel.
1. Pick the **Identity service** and **Server**.
2. Enter your **Username** and **Password**, then **Sign in**. **Register** creates an account
where the service allows it.
3. If two-factor authentication is on, enter the **Verification code** (use **Resend code** if
it didn't arrive).
Your session token is kept in the browser's local storage. **Sign out** removes it.
Esc closes the dialog.
## Live sync
Once you're signed in, the same dialog shows a **Sync server** field (default
`wss://sync.trisgine.com/sync/v3`) with **Connect** and **Disconnect** buttons.
The toolbar's **Sync** pill shows the state:
| Colour | Meaning |
|---|---|
| blue | signed out |
| grey | offline |
| yellow | connecting, or receiving the shared world |
| green | **Live**: edits flow both ways |
| orange | reconnecting |
Sync shares *authoring* edits (moving things, changing values) between people working on the
same world. It is live while the simulation is **stopped**. While you play, your copy runs
on its own.
> [!NOTE]
> In the web editor, creating and deleting entities still applies only locally, while field
> edits do sync. Expect this to change as sync matures.
---
# Keyboard shortcuts
URL: https://wiki.trisgine.com/editor/shortcuts/
Every shortcut in the web editor, grouped by where it works.
**Help > Keyboard Shortcuts** shows the same list inside the editor. On the web, Ctrl
is the modifier on every platform.
## Editor
| Shortcut | Action |
|---|---|
| Ctrl+Z | Undo |
| Ctrl+Shift+Z or Ctrl+Y | Redo |
## Scene (Scene view or Hierarchy focused)
| Shortcut | Action |
|---|---|
| Ctrl+S | Save scene |
| Ctrl+D | Duplicate |
| Del | Delete |
| F2 | Rename |
| Q W E R T | Hand · Move · Rotate · Scale · Universal |
| F | Frame selection |
| hold Ctrl while dragging | Snap |
## Scene navigation
| Input | 3D | 2D |
|---|---|---|
| Right mouse drag | look | pan |
| Right mouse + WASD / arrows | fly | n/a |
| Right mouse + Q / E | down / up | n/a |
| Right mouse + Shift / Ctrl | 2× / ½× speed | n/a |
| Right mouse + wheel | fly speed | n/a |
| Middle mouse drag | pan | pan |
| Wheel | forward / back | zoom |
## Project panel
| Shortcut | Action |
|---|---|
| Ctrl+D | Duplicate asset |
| Del / F2 | Delete / rename asset (not available on the web yet) |
## Pixel Art and Tilemap
| Shortcut | Action |
|---|---|
| Space | play / pause animation |
| Ctrl+S / Ctrl+Shift+S | save / save as |
| Esc / Enter | cancel / commit a selection |
| Ctrl+C / Ctrl+V | copy / paste as a floating selection |
| [ / ] | smaller / larger brush |
## Node graphs (Script, Shader and Particle editors)
| Shortcut | Action |
|---|---|
| Space | node search palette |
| drop a wire on empty space | add a node that is already connected |
| Ctrl+right-drag | cut wires |
| Shift+click a wire | add a reroute point |
| Alt+drag | detach a node |
| Ctrl+C / V / D | copy / paste / duplicate |
| Ctrl+X | delete and reconnect around it |
| Del | delete |
| M | bypass (mute) node |
| Ctrl+J / F | frame selection / frame all |
| F1 or ? | help |
## Playing (mouse over the Simulation panel)
| Input | Action |
|---|---|
| WASD / arrows | walk |
| Q / E | down / up |
| Shift / Ctrl | 5× / ½× speed |
| mouse | look |
| Esc | release cursor |
---
# Sprites & the 2D camera
URL: https://wiki.trisgine.com/2d/sprites/
Putting pixel-art sprites on screen, ordering them, tinting them and looking at them through a 2D camera.
2D in Trisgine uses its own lightweight entities: a **sprite** has a 2D position, an angle,
a 2D scale, a draw order and a tint. It does not use the 3D transform. Sprites are drawn by
the **Sprite2DRendering** system, from a **2D camera**.
## A minimal 2D scene
Here is the smallest complete 2D scene, a camera and one sprite, written as a
[scene file](/reference/scene-format/):
```tgscene
configs:
update:
input:
render:
-Sprite2DRendering
entities:
-Camera2DMain:
-Camera2D:10
-Position2D:0,0
-Hero:
-Sprite:7A11C0DE00000004
-Position2D:0,0
-Scale2D:1,1
-ZOrder:10
-Tint:1,0.6,0.2,1
```
`Camera2D:10` means the camera shows **10 world units vertically**. The width follows the
panel's aspect ratio, so a bigger number zooms out.
## In the editor
- **Create a sprite**: right-click the Hierarchy, then **2D Sprite**. It starts with a plain
white texture.
- **Create a 2D camera**: make an entity (**Create Empty**), then **Add Component > 2D Camera**.
- Select a sprite and the Inspector shows its **Transform 2D** section: position, angle, scale,
Z-order and tint.
- Toggle **2D** in the Scene view's toolbar to edit in a flat view.
| Field | Scene line | Notes |
|---|---|---|
| Position | `-Position2D:x,y` | world units |
| Angle | `-Angle2D:degrees` | counter-clockwise |
| Scale | `-Scale2D:x,y` | a **negative** value flips the sprite |
| Z-order | `-ZOrder:n` | higher draws on top (−32767…32767) |
| Tint | `-Tint:r,g,b,a` | multiplies the image; `a` < 1 is see-through |
| Image | `-Sprite:` | see below |
> [!NOTE]
> To change a sprite's image, click the image slot in its **Transform 2D** section and pick a
> texture (type in the filter to find it). [Meadow Quest](/rpg2d/3-hero-and-camera/) does this
> for every sprite.
## Movement without code
Give a sprite `-Velocity2D:x,y` and it moves on its own (the **MoveByVelocity2D** system
is added automatically). Add **Bounce2D** to the `update:` list and sprites bounce off the
camera edges, which makes a classic screensaver.
## Moving sprites with scripts
[Visual scripts](/logic/visual-scripting/) control sprites with 2D nodes: **SetVelocity2D**,
**GetPosition2D** / **SetEntityPosition2D**, input actions (**ActionVector2** *Move*,
**ActionPressed** *Jump*) and **FindEntity** to look at other entities. A script moving a
**Camera2D** makes it follow a sprite.
[Meadow Quest](/rpg2d/overview/) builds a complete top-down RPG with them.
## What 2D can't do yet
- Sprites can't be parented to other sprites.
- Scripts can't spawn or destroy sprites; move them out of sight instead.
---
# Pixel Art editor
URL: https://wiki.trisgine.com/2d/pixel-art-editor/
Painting sprites and textures in the browser, with layers, animation frames, palettes and optional AI generation.

Open it from **Windows > Pixel Art**, or double-click any image in the Project panel.
## Canvas and tools
| Tool | Does |
|---|---|
| Pencil | paint single pixels (brush size with [ ]) |
| Eraser | clear to transparent |
| Picker | pick a colour from the canvas |
| Flood fill | fill a connected area |
| Line / Rectangle / Ellipse | shapes (outline or filled) |
| Select | marquee. Ctrl+C / Ctrl+V paste as a floating selection; Enter commits |
The right side has the **layer** stack (opacity, blend mode, Dup / Up / Down / Merge) and the
**colour picker** with hex input, recent colours and shades. Palettes load and save as
GIMP `.gpl` files.
Also available:
- **Mirror modes**: paint symmetrically, horizontally, vertically or diagonally.
- **Tile preview**: shows the image repeated, to check that a texture tiles seamlessly.
- **Autosave**: keeps a recovery copy while you work.
## Animation
The frame strip under the canvas adds, duplicates, removes and reorders frames. **Onion skin**
shows the neighbouring frames, the fps field sets the speed, and Space plays it.
## Saving
| Save as | Use for |
|---|---|
| **Layered (.tgpx)** | keep layers and frames for later editing |
| **Flattened image (.png)** | a texture for materials, sprites or tiles |
| **Flipbook strip (.png)** | all frames side by side, ready for sprite animation |
| **Sprite sheet (.png)** | frames in a grid |
A saved `.png` gets a UUID immediately, and any material or sprite using it **updates live**.
> [!TIP]
> For 3D materials, paint small (16×16 or 32×32) and keep the pixels crisp: the engine
> samples them as pixel art.
## AI generation (optional)
The bottom of the window has a prompt field (*"describe what to draw…"*) and a **Generate**
button. They talk to an image model **you run yourself** (ComfyUI), and a second field
(*"which part? e.g. make the cape red"*) uses a local language model (Ollama) to pick a region
to recolour. Setup and tips: [Pixel art generation](/ai/pixel-art-generation/).
---
# Tilemaps
URL: https://wiki.trisgine.com/2d/tilemaps/
Painting grid-based levels with the Tilemap window and placing them in a 2D scene.
A **tilemap** is a grid of tiles, where each tile is a texture. It is stored in one
`.tgtilemap` file and drawn by a single entity.
## Making one
1. **Project > Create > Tilemap**, or **Windows > Tilemap > New**.
2. **Add tile** for each texture you want to paint with (paint them first in
[Pixel Art](/2d/pixel-art-editor/)).
3. Paint with the tools:
| Tool | Does |
|---|---|
| Brush | paint the selected tile (or a multi-tile **stamp**) |
| Eraser | clear cells |
| Rect | fill a rectangle |
| Fill | flood-fill an area |
| Select | pick a region to copy or move |
4. Use **+ Layer / − Layer** for ground, decoration and overlay layers. Each layer has its own
draw order.
5. Use **Resize…** to change the grid size, and **random rotation / mirror** to break up
repetition.
6. **Save**.
> [!TIP]
> If you save a brand-new map with **Save As…** and it then doesn't appear in **Add Component >
> Tilemap**, create the map from the Project panel instead: right-click a folder, **Create >
> Tilemap**, then double-click it to paint. Maps created that way are listed immediately.
## Putting it in a scene
Drag the `.tgtilemap` from the Project panel into the Hierarchy (empty area) or the Scene
view. Or select an entity with a 2D position and use **Add Component > Tilemap**. The entity's
position is the map's **bottom-left corner**, and each cell is one world unit.
```tgscene
-DemoMap:
-Position2D:0,0
-Tilemap:B3B79A79FE32ED40
```
Tiles from a map show greyed out in the Hierarchy. Edit them in the Tilemap window, not one by one.
## The file format
`.tgtilemap` is plain text, so it's easy to generate with a script or an AI:
```text
tilemap 1
size 10 6
cell 1
tileset 2
0 7F4A09AFD320074C any
1 F773BD1015D0DE41 fixed
layer Ground 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
layer Decor 50 1
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
1 1 1 1 1 1 1 1 1 1
```
- `size W H` is the grid size, and `cell 1` is the cell size in world units.
- `tileset N` is followed by `index textureUUID any|fixed` lines. `any` allows random rotation
and mirroring of that tile; `fixed` keeps it upright.
- `layer Name z visible` is followed by `H` rows of tile indices. `.` is an empty cell, and the
first row is the **top** of the map.
> [!NOTE]
> Tiles have no collision yet. For walls, add separate invisible
> [2D colliders](/2d/physics-2d/) on top of the map.
---
# 2D physics
URL: https://wiki.trisgine.com/2d/physics-2d/
Colliders, bodies, sensors, joints and gravity for 2D sprites.
Trisgine ships a 2D rigid-body solver with circles and boxes, static, dynamic and kinematic
bodies, sensors, joints and collision layers.
## The two components
**Collider2D** gives a sprite a shape. A sprite with a collider but **no body** is static:
walls, floors and level geometry.
```tgscene
-Collider2D:box,halfWidth,halfHeight[,offsetX,offsetY,material][,sensor]
-Collider2D:circle,radius[,offsetX,offsetY,material][,sensor]
```
**PhysicsBody2D** makes it move under physics:
```tgscene
-PhysicsBody2D:mass,linearDamping,angularDamping[,flags,angularVelocity,gravityScale]
```
Flags can be combined: `kinematic`, `fixedrotation`, `ccd`, `nosleep`, `reportscollisions`.
A dynamic body also needs a `-Velocity2D:x,y` line, even if it starts at `0,0`.
## Scene setup
Add `Physics2DStep` to the `update:` list, and optionally a `Physics2D` config. Its first two
values are gravity:
```tgscene
configs:
-Physics2D:0,-9.81,0.0041667,8
update:
-MoveByVelocity2D
-Physics2DStep
render:
-Sprite2DRendering
```
> [!TIP]
> Making a **top-down** game? Set gravity to zero: `-Physics2D:0,0,0.0041667,8`.
## A falling crate and a trigger zone
This is the engine's sensor demo: the crate falls *through* the blue zone (sensors detect,
they don't push) and lands on the floor.
```tgscene
-Floor:
-Sprite:4931169A6F314FE5
-Position2D:0,-7
-Scale2D:13.6,1
-Collider2D:box,6.8,0.5,0,0,rock
-TriggerZone:
-Sprite:4931169A6F314FE5
-Position2D:0,-2
-Scale2D:8,2
-Tint:0.30,0.60,1,0.35
-Collider2D:box,4,1,0,0,0,sensor
-FallingCrate:
-Sprite:3D94E7A1C5B20F86
-Position2D:0,6
-Velocity2D:0,0
-Collider2D:box,0.5,0.5,0,0,wood
-PhysicsBody2D:1,0,0
```
## Joints
```tgscene
-Joint2D:distance|rope|spring,,restLength[,stiffness,damping][,breakForce]
```
## Tools
- **Windows > Physics** lists every collider and body live, with its velocity and whether it
is sleeping. Click a row to select it.
- The toolbar's **physics freeze** and **substep** buttons pause the solver alone and step it
one substep at a time.
- The Scene view's **Debug view** colours static, dynamic and kinematic shapes.
## Current limits
Scripts react to contacts with **OnTriggerEnter** / **OnTriggerExit** (a collider with **Is sensor
(trigger)** ticked) and **OnCollisionEnter** / **OnCollisionExit** (solid hits; tick **Reports
collisions** on one of the two Physics Body 2Ds). **ContactOther** gives the other entity. Meadow
Quest's coins are [triggers](/rpg2d/12-sounds-and-triggers/). The `ImpactAudio2D` system plays
impact sounds without any script.
---
# Sprite animation
URL: https://wiki.trisgine.com/2d/animation/
Flipbook animation from sprite sheets, and cutout rigs.
## Flipbooks
A sprite animates automatically when its texture is a **sprite sheet** and the texture's
`.mt` sidecar describes the grid:
```text
atlas:4,1,4,6
uuid:E0E2E5C73B79CFB1
```
`atlas:columns,rows,frames,fps`, so this example is a 4×1 strip with 4 frames at 6 frames
per second. Any sprite that uses this texture loops through the frames, as long as the scene's
`update:` list contains **Sprite2DFlipbook**.
### From the Pixel Art editor
1. Draw your frames in [Pixel Art](/2d/pixel-art-editor/). Use the frame strip and onion skin.
2. **Save as > Flipbook strip (.png)**. The frames are laid out side by side.
3. Add the `atlas:` line to the image's `.mt`. To do that in the browser, edit the `.mt`
on your computer and import the image again together with it.
## Cutout rigs
A **rig** (`.tgrig`) animates a character made of separate parts (bones and slots) with
keyframed rotation clips, and it can blend between clips. Place one with `-Rig:` and
add **Rig2DAnimation** to `update:`.
> [!NOTE]
> A sprite plays **one looping clip**. Nothing yet switches clips by direction or state
> (walk-left vs walk-right, idle vs run).
---
# Visual scripting
URL: https://wiki.trisgine.com/logic/visual-scripting/
Giving objects behaviour with node graphs in the Script Editor, with no code and no compiler to install.

A **visual script** (`.tgscript`) is a small node graph that runs **once per frame for every
entity it is attached to**. The editor compiles it to WebAssembly in the browser.
## The Script Editor
Open **Windows > Script Editor**. Its toolbar:
| Button | Does |
|---|---|
| **New** | creates `Assets/Scripts/.tgscript` with a starter graph |
| **Open** | opens an existing script |
| **Save** | writes the file. Attached entities pick it up. |
| **Compile** | checks and compiles. The status reads e.g. *compiles (1 handler)*. |
| **Arrange** / **Frame** | tidy the layout / zoom to fit |
| **Graph · Text · Split** | edit as nodes, as text, or both side by side |
Working with nodes:
- Space opens the **node search**. Type `Branch`, `KeyDown`, `SetPosition` and so on.
- Drag from an output pin to an input pin to connect them. Drop a wire on empty space to
create a node that is already wired up.
- **White** (exec) wires set the order things happen in. **Coloured** wires carry values:
numbers, vectors, true/false.
- The **Text** tab is the same graph as readable JavaScript-like text. Edit either side and the
other follows. The graph is the source of truth; the text is a view of it.
If a graph can't run (for example, it reads a component the entity doesn't have), the
editor lists a **refusal** that explains why, instead of silently doing nothing.
## Attaching a script
1. Select a **3D object** (a mesh primitive or an imported mesh) in the Hierarchy.
2. In the Inspector, scroll to the **Script** section and click the slot that reads *(none)*.
3. Pick your `.tgscript`.
The same script can be attached to many entities, and each one runs it on its own data.
Attaching a script automatically schedules the **ScriptRun** system.
## Your first script: drift
The starter graph from **New** already works: it moves the object by its own velocity.
Here is an even simpler one that slides an object along +X at 1.5 units per second:
```tgscript
//!tgscript v1
//! script name=Drift
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetPosition pos=(260,80)
const n2_value = ctx.getPosition();
//! node 3 ConstVec3 pos=(260,200)
const n3_value = ctx.vec3(1.50, 0.00, 0.00);
//! node 4 DeltaTime pos=(260,320)
const n4_value = ctx.deltaTime();
//! node 5 ScaleVec3 pos=(460,240)
const n5_out = ctx.scaleVec3(n3_value, n4_value);
//! node 6 AddVec3 pos=(660,140)
const n6_out = ctx.addVec3(n2_value, n5_out);
//! node 7 SetPosition pos=(860,140)
ctx.setPosition(n6_out);
}
//! endregion
```
Read it as a graph: **OnUpdate** → **SetPosition**( **GetPosition** + **ConstVec3** ×
**DeltaTime** ). Paste it into the **Text** tab to see the nodes appear.
## Reacting to the player
Every 3D object knows its squared distance to the player camera, through the
**DistanceToPlayerSquare** component (enable the system of the same name in the scene).
Compare it with a constant to make things react when the player comes close:
```tgscript
//! node 2 GetNumber pos=(260,80) component=DistanceToPlayerSquare
const n2_value = ctx.getNumber("DistanceToPlayerSquare");
//! node 3 ConstNumber pos=(260,200)
const n3_value = 4.00;
//! node 4 Greater pos=(460,120)
const n4_out = (n3_value > n2_value);
//! node 5 Branch pos=(660,80)
if (n4_out) {
// ...do something when the player is within 2 m (2 × 2 = 4)
}
```
> [!TIP]
> It's a *squared* distance, so square your radius: 2 m → `4`, 4 m → `16`, 5 m → `25`.
## Reacting to keys: a four-direction mover
`KeyDown` reads the keyboard while the game runs. Several `Branch` nodes can run one after
another, and the last `SetVelocity` wins:
```tgscript
//! node 2 ConstVec3 pos=(60,240)
const n2_value = ctx.vec3(0.00, 0.00, 0.00);
//! node 3 SetVelocity pos=(260,80)
ctx.setVelocity(n2_value);
//! node 4 KeyDown pos=(260,240) key=I
const n4_value = ctx.keyDown("I");
//! node 5 Branch pos=(460,80)
if (n4_value) {
//! node 6 ConstVec3 pos=(460,240)
const n6_value = ctx.vec3(0.00, 0.00, 4.00);
//! node 7 SetVelocity pos=(660,80)
ctx.setVelocity(n6_value);
}
// ...repeat for K (back), J (left), L (right)
```
The object stops when no key is held, because the first `SetVelocity` sets zero every frame.
The scene needs **MoveByVelocity** in its `update:` list to turn velocity into movement.
> [!NOTE]
> We used I/J/K/L here so it doesn't clash with the first-person camera's W/A/S/D. If your
> scene has no `FreeLookCamera`, W/A/S/D are free to use.
## System order matters
Scripts run where **ScriptRun** sits in the scene's `update:` list. Put it **after** the
systems whose results it reads (for example `DistanceToPlayerSquare`) and **before**
`WorldMatrix`, which turns positions into what you see:
```tgscene
update:
-MoveByVelocity
-RotateByAngularVelocity
-DistanceToPlayerSquare
-ScriptRun
-WorldMatrix
```
If `ScriptRun` comes first, the distance on the very first frame reads 0, and every
"player is near" check fires at once.
## What scripts can and can't do (today)
| Can | Can't (yet) |
|---|---|
| read/write their own **position** and **velocity** | read or change **other** entities |
| read **DistanceToPlayerSquare**, other single-number and vector components | move **2D sprites** (they use 2-lane positions) |
| read the **keyboard** (`KeyDown`) | keep variables between frames (other than in components) |
| branch on comparisons | strings, text, dialogue |
| run on **UI elements** (`OnUiEvent`, `UiClicked`, `UiCommand`) | react to collisions or triggers |
| add/remove tag components | spawn or destroy entities, change scenes |
Full list: [Script node reference](/logic/script-nodes/).
> [!NOTE]
> Several of the "can't" items are being worked on. The next version of visual scripting adds 2D position/velocity nodes, named input actions with gamepad support,
> `FindEntity` + `GetEntityPosition2D`, and vector and logic helpers (`Abs`, `Less`, `And`,
> `MakeVec2`…). This page will be updated when it ships to production.
---
# Scripting best practices
URL: https://wiki.trisgine.com/logic/best-practices/
How to write visual scripts that work with the engine instead of against it, with examples from Meadow Quest.
A visual script runs once per frame, inside a pipeline of engine **systems**. In a 2D scene
the order is:
```text
ScriptRun → MoveByVelocity2D → Physics2DStep → Sprite2DRendering
(your scripts) (applies velocity) (bodies, collisions) (draws)
```
Your script decides **what should happen**; the systems after it do the moving, colliding and
drawing. The practices below follow from that.
## Move things by setting velocity
Set **SetVelocity2D** (or **SetEntityVelocity2D**) to a speed in units per second, and let the
engine integrate it.
| | Set velocity | Write position every frame |
|---|---|---|
| frame-rate independent | yes, the engine multiplies by the frame time | only if you multiply by **DeltaTime** yourself |
| collides with walls | yes, the physics step stops a body at a wall | no, it teleports through |
| other systems see the motion | yes: physics and anything else that reads velocity | no, they see a jump |
| stops cleanly | set velocity 0 | must stop writing |
In Meadow Quest the hero, the dog and the slimes all move by velocity. A sprite needs a
velocity to have one: **Add Component > Velocity x,y**, or **Physics Body 2D**, which brings a
velocity and a collider together.
**Writing the position is right for:** a camera that follows exactly, HUD elements pinned to
the camera, and one-off jumps (a coin moving away when collected, the hero respawning).
## Let physics own physical things
- Anything that must be **blocked by walls** or **push other things** gets a **Physics Body 2D**,
and is moved only by velocity.
- Things that never move and only block (walls) get a **Collider 2D** without a body: they're
static and cost almost nothing.
- Top-down games: **Gravity scale** 0 on every body, **Fixed rotation** on characters.
## Keep state in one place
| Kind | Use for | Meadow Quest example |
|---|---|---|
| **Global** (GetGlobal / SetGlobal) | game state shared by many scripts | `coins`, `hp`, `hasSword`, `started` |
| **Variable** (GetVar / SetVar) | memory belonging to one entity | the sword's `face` and `swingAt` |
| **Component values** | anything the engine also reads | position, velocity, tint |
Scripts that **display** state (hearts, inventory icons, speech bubbles) read it every frame and
place their sprites to match; they never keep their own copy. That way the picture can't drift
out of step with the game.
Globals and variables reset when you press **Stop**. Use **OnStart** to set starting values
that aren't 0 (like 3 hearts).
## Make every frame's decision complete
A script runs every frame, so give each **Branch** an `else` that undoes what `then` did: show
the bubble or park it, chase or stop. A branch without an `else` leaves the last frame's result
behind.
For **one-off events** (a key press, a hit), use **ActionPressed** (true for one frame only), or
store a time and compare with **Time**, as the sword swing and the hit cooldown do.
## One script, many entities
Write a script for **a kind of thing**, not for one object: all coins share `Coin`, both slimes
share `Slime`. **GetPosition2D**, **SetVelocity2D** and the other nodes without an entity input
act on the entity running the script. Use **FindEntity** only for named, unique things (the
hero, the camera).
## Split by job, not by object
`Health` and `Inventory` are separate scripts even though both draw HUD: each has one job and a
graph you can read. When a graph no longer fits on the screen after **Frame**, split it.
## Read input as actions
Read **ActionVector2** / **ActionPressed** (*Move*, *Jump*, *Fire*) rather than **KeyDown**
where you can: actions cover keyboard and gamepad, and their bindings can be changed in
**Windows > Input Actions** without editing scripts. **KeyDown** is fine for a debug key or a
one-off like the potion's Q.
## Order matters in the scene's system list
Keep **ScriptRun** before **MoveByVelocity2D** and **Physics2DStep** in the scene's `update:`
list (the order Meadow Quest's scene uses), so a velocity set this frame is applied this frame.
This matters if you edit a `.tgscene` by hand or with an AI agent.
## Use events for things that happen once
**OnTriggerEnter** (a sensor collider was entered), **OnCollisionEnter** (a solid hit; tick
**Reports collisions** on one of the Physics Body 2Ds), **OnMessage** and **OnUiEvent** run only when
something happens. Prefer them to checking a condition every frame: a pickup on a trigger is exact
and costs nothing between contacts. Compare **ContactOther** with the entity you expect, since
anything with a body can enter a trigger.
Side effects such as **PlayAudio**, **SetText** and **LoadScene** belong on those events, or behind
a flag that makes them run once (the Meadow Quest gate's `open` variable). Called every frame, a
sound restarts every frame.
## Things that aren't possible yet
Knowing the limits saves hours:
- spawning or destroying entities (park them far away);
- loading a *different* scene from a script while in the editor (it works in a published game;
in the editor **LoadScene** only restarts the open scene).
See [What's next](/rpg2d/12-whats-next/#not-possible-yet-and-whats-coming) for the full list.
---
# Script node reference
URL: https://wiki.trisgine.com/logic/script-nodes/
Every node available in .tgscript visual scripts, with its pins, attributes and text form.
Pin types: **Number** (a float), **Vec3** (x, y, z), **Bool**. Exec pins (white) are `in` and
`next`; a **Branch** has `then` and `else`.
## Events
| Node | Text form | Runs |
|---|---|---|
| **OnStart** | `export function onStart(ctx)` | once, when the entity first runs the script |
| **OnUpdate** | `export function onUpdate(ctx)` | every frame |
| **OnUiEvent** | `export function onUiEvent(ctx)` | when the UI element it is attached to gets input |
## Values
| Node | Output | Attribute | Text form |
|---|---|---|---|
| **DeltaTime** | Number | | `ctx.deltaTime()` (seconds since the last frame) |
| **GetPosition** | Vec3 | | `ctx.getPosition()` |
| **GetVelocity** | Vec3 | | `ctx.getVelocity()` |
| **KeyDown** | Bool | `key=` | `ctx.keyDown("Space")` |
| **ConstNumber** | Number | | `1.50` |
| **ConstVec3** | Vec3 | | `ctx.vec3(x, y, z)` |
| **AddNumber** | Number | | `(a + b)` |
| **MulNumber** | Number | | `(a * b)` |
| **AddVec3** | Vec3 | | `ctx.addVec3(a, b)` |
| **ScaleVec3** | Vec3 | | `ctx.scaleVec3(v, s)` |
| **Greater** | Bool | | `(a > b)` |
| **Equal** | Bool | | `(a === b)` |
| **GetNumber** | Number | `component=` | `ctx.getNumber("DistanceToPlayerSquare")` |
| **GetVec3** | Vec3 | `component=` | `ctx.getVec3("Velocity")` |
| **UiClicked** · **UiHoverEnter** · **UiValueChanged** · **UiValueCommitted** | Bool | | `ctx.uiClicked()`, … |
| **RerouteNumber / Vec3 / Bool** | pass-through | | tidy long wires |
`KeyDown` accepts the keys **A–Z**, **0–9**, **Space**, **Escape**, **Enter**, **Tab**,
**Backspace**, **Delete**, the arrow keys, and left/right **Shift**, **Control** and **Alt**.
## Actions
| Node | Input | Attribute | Text form |
|---|---|---|---|
| **SetPosition** | Vec3 | | `ctx.setPosition(v)` |
| **SetVelocity** | Vec3 | | `ctx.setVelocity(v)` |
| **SetNumber** | Number | `component=` | `ctx.setNumber("Name", n)` |
| **SetVec3** | Vec3 | `component=` | `ctx.setVec3("Name", v)` |
| **AddComponent** / **RemoveComponent** | | `component=` | `ctx.addComponent("Name")` |
| **UiCommand** | | `command=` | `ctx.uiCommand("game.new")` |
## Flow
| Node | Text form |
|---|---|
| **Branch** | `if (cond) { … } else { … }` |
## More nodes
Newer nodes, by group. Each shows its inputs as pins; the Script Editor's palette (Space)
searches them all.
| Group | Nodes |
|---|---|
| Events | **OnTriggerEnter** · **OnTriggerExit** · **OnCollisionEnter** · **OnCollisionExit** (with **ContactOther**, **ContactPoint**, **ContactNormal**) · **OnMessage** (with **MessageIs**, **MessageValue**, **MessageSender**) |
| Input | **ActionPressed** · **ActionReleased** · **ActionHeld** · **ActionValue** · **ActionVector2** · **SetActionMapEnabled** |
| Logic & maths | **Less** · **LessEqual** · **GreaterEqual** · **NotEqual** · **And** · **Or** · **Not** · **Min** · **Max** · **Abs** · **Clamp** · **SubNumber** · **DivNumber** · **Time** · **Every** · **Random** · **RandomRange** |
| Memory | **GetVar** / **SetVar** (one entity) · **GetGlobal** / **SetGlobal** (every script) · **GetVarVec3** / **SetVarVec3** |
| 2D | **GetPosition2D** / **SetPosition2D** · **GetVelocity2D** / **SetVelocity2D** · **GetAngle2D** / **SetAngle2D** · Vec2 maths (**Vec2Normalize**, **Vec2Distance**, **Vec2ToAngle**, …) |
| Other entities | **FindEntity** · **FindByTag** · **Get/SetEntityPosition(2D)** · **Get/SetEntityVelocity(2D)** · **SendMessage** |
| Physics queries | **Raycast2D** (+ **Raycast2DEntity**, **…Point**, **…Normal**, **…Distance**) · **OverlapCircle2D** · **OverlapBox2D** (+ **…First**) |
| Game | **SetText** · **SetTextNumber** (UI text) · **PlayAudio** · **StopAudio** (an entity's Audio Source) · **LoadScene** · **CameraFollow2D** |
Pins named `entity`, `element`, `camera` or `target` mean "this entity" when nothing is wired to
them. **SetText**, **PlayAudio** and **LoadScene** take effect at the end of the frame.
## Attributes and components
`component=` names a component by its short name, for example `DistanceToPlayerSquare`,
`Velocity` or `Position`. If a component has several fields, name one: `Name.field`. The
compiler refuses, with a message, any component that doesn't exist, has no value (a tag), or
is stored in a format scripts can't touch.
> [!TIP]
> Write simple attribute values **without quotes** (`key=W`, `component=DistanceToPlayerSquare`).
> Some editor builds reject quoted values there. Only values with dots or colons, such as
> UI commands (`command="game.new"`), need quotes.
## The text format
```tgscript
//!tgscript v1
//! script name=MyScript
//! region graph
//! node pos=(x,y) [attribute=value]
export function onUpdate(ctx) {
...one statement per node...
}
//! endregion
```
- Each node is one `//! node` annotation line, followed by its statement.
- **Data wires** come from variable names: `n4_out` is node 4's output, and using it in
node 7's statement wires 4 → 7. Values are named `nN_value` (value nodes) or `nN_out`
(operators).
- **Exec order** is the order of the statements, and `if / else` blocks are Branch outputs.
- Lines outside `//! region graph` are free-form comments that the editor keeps.
This format is designed so that a person *or an AI* can write a script in a text editor and
paste it into the **Text** tab. See [Authoring scripts with AI](/ai/authoring-scripts/).
---
# Game UI
URL: https://wiki.trisgine.com/logic/game-ui/
Canvases, panels, text and buttons for menus and HUDs.
Trisgine's UI system draws **canvases** of elements, either on screen (menus, HUD) or in
the world (signs, screens on a wall).
## Building UI in the editor
1. Right-click the Hierarchy, then **UI > Canvas (Screen)** for a HUD or menu, or
**Canvas (World)** for something placed in 3D.
2. With the canvas selected, add elements: **UI > Panel, Button, Text, Image, Toggle, Slider,
Scroll View, Dropdown**.
3. Select an element to edit its anchors, size, colour, text style and more in the Inspector.
**Add Component** offers UI extras: *Text Style*, *Auto-Layout Container*, *State Style*,
*Toggle*, *Slider*, *Scroll View*, *Dropdown* and *3D Viewport*.
4. **Save Scene** also writes the canvas to a `.uidoc` file.
## The `.uidoc` format
Canvases are stored as indented text:
```text
canvas UiDocMenu space=screen w=1920 h=1080
panel UiDocPanel preset=center w=50% h=50% tint=1,0.2,0.2,1
text UiDocTitle preset=top-center w=320 h=48 size=40 align=center valign=middle text=@menu.title
button UiDocPlay w=200 h=64
```
- Two spaces of indentation per level.
- Element kinds: `panel`, `button`, `text`, `image`, `toggle`, `slider`, `scroll`, `dropdown`.
- Common keys: `preset=` (anchoring, e.g. `center`, `top-center`), `w=` / `h=` (pixels or
`%`), `tint=`, `text=` (a literal, or `@key` for a [localized](#localization) string),
`size=`, `align=` / `valign=`, `sprite=`, `layout=hstack|vstack|grid`.
A scene lists its canvases by UUID in a `ui:` block, and needs the UI systems in `update:` and
`render:`:
```tgscene
ui:
-7D1C4B90A3E52611
update:
-UiCanvasMetrics
-UiHierarchy
-UiTextShape
-UiLayout
-UiViewport
-UiInput
-UiShortcut
-UiScriptRun
render:
-UiScreenRendering
-UiWorldRendering
```
## Making buttons do things
Attach a visual script to a UI element and use **OnUiEvent** + **UiClicked** → **Branch** →
**UiCommand**. Commands are the built-in game-menu actions: `game.new`, `game.continue`, page and tab
navigation, `settings`, save-slot actions, `dialog.yes` / `dialog.no` and `app.exit`. They
need the **GameMenuModel** system in the scene.
```tgscript
//! node 1 OnUiEvent pos=(60,80)
export function onUiEvent(ctx) {
//! node 2 UiClicked pos=(60,200)
const n2_value = ctx.uiClicked();
//! node 3 Branch pos=(260,80)
if (n2_value) {
//! node 4 UiCommand pos=(460,80) command="game.new"
ctx.uiCommand("game.new");
}
}
```
Commands with dots or colons are written in quotes, as above.
## Changing text from gameplay
**SetText** writes a fixed string into a UI Text element, and **SetTextNumber** writes a prefix
followed by a number (`Score: ` and `12` show *Score: 12*). Wire **FindEntity** with the element's
name into their `element` input. A SetText string that starts with `@` is a
[localization](#localization) key. See [Meadow Quest's quest line](/rpg2d/13-quest-text/) for a
worked example.
## Localization
Text that starts with `@` is a key looked up in the active language: `text=@menu.title`. See
[Localization](/logic/localization/) for the panel, the CSV workflow and what works on web.
---
# Localization
URL: https://wiki.trisgine.com/logic/localization/
Translate UI text into several languages with @keys and per-language tables, and switch language in the editor.

## How it works
- UI **Text** whose string starts with `@` is a **key**, not text: `@menu.newgame` shows "New
Game" in English and "Neues Spiel" in German.
- Each language is one table in `Assets/Localization/`, named by its code: `en.tgloc`,
`de.tgloc`, and so on. **English (`en`) is the master list** of keys; add a key there first.
- A key missing from the active language falls back to the English text. A key missing
everywhere shows as `⟪key⟫`, so it's easy to spot.
- Translations travel as **CSV** (`key,en,de,…`, one row per key); the tables themselves are
a compact binary format you don't edit by hand. **Project > Import** refuses `.csv` and
`.tgloc` files; use the Localization panel.
## The Localization panel
Open **Windows > Localization**.
| Part | What it does |
|---|---|
| **Active language** | the language the editor shows now, its key count, and a button per available language. Click one to switch: every `@key` text on screen changes at once. |
| **Compare with** | adds another language as an extra column in the grid, side by side. **Clear columns** removes them. |
| path, **Export CSV** | saves the grid (the key, the active language and any compared columns) as CSV: the web editor downloads it, the desktop editor writes it to the path |
| language code, **All columns**, **Import CSV…** | imports the column with that code, or every language column with **All columns** ticked: the web editor opens a file chooser, the desktop editor reads the path. Each imported column replaces that language's table |
| **Rescan** | looks for new language tables |
| the grid | every key with its text; `(missing)` marks a key without a translation |

## How to translate a game
1. Write your UI texts as keys: in a Text element's **Text Style** box type `@title.start`
instead of `Start`. Use dotted names by screen or topic (`menu.…`, `hud.…`, `dlg.…`).
2. Keep **en** active, **Compare with** every other language, and **Export CSV** to get the
whole table.
3. Add your keys as rows, and a column per new language (for example `cs` for Czech), in any
spreadsheet. Keep the first column `key` and the column names equal to the language codes.
Save as CSV, UTF-8.
4. Tick **All columns** and click **Import CSV…**. A new language appears under *Active
language*; click it to check.
> [!WARNING]
> An import **replaces** each imported language's whole table, so always start from an export.
> The import refuses the whole file, writing nothing, if a key is missing from `en`, duplicated or
> malformed, or a cell isn't UTF-8. Web CSV import and download need an editor from 18 October 2026
> or later; older web editors can only view, compare and switch languages.
## Switching language in the game
The panel switches the language in the editor. For players, a dropdown wired to the built-in
game-menu system switches it; [Meadow Quest's menu](/rpg2d/15-main-menu/) shows how. A script's
**SetText** can show keys (`@quest.talk`), see [Part 16](/rpg2d/16-languages/).
## Good practices
- **Never type player-facing text directly** in a game you might translate: use a key from the
start. Retrofitting keys later means touching every screen.
- **Keep `en` complete.** It's the fallback for every other language, so a missing English
string shows as `⟪key⟫` everywhere.
- **Leave room.** German and Czech strings are often a third longer than English; size buttons
and boxes for the longest language, or use **Overflow: Wrap** in **Text Style**.
- **Text painted into images can't be translated.** Speech bubbles drawn as sprites (as in
[Meadow Quest](/rpg2d/9-npc-farmer/)) stay in the language they were painted in.
- **Check with Compare.** Add the other languages as columns and look for `(missing)` before you
publish.
---
# Audio
URL: https://wiki.trisgine.com/logic/audio/
Importing sounds, placing audio sources in the world, and reverb.
## Getting sounds in
[Import](/editor/project-browser/#importing-files) `.wav`, `.ogg`, `.mp3` or `.flac` files.
Select a clip in the Project panel to hear it and see its waveform in the Inspector.
> [!NOTE]
> Browsers keep audio silent until you click or press a key on the page. If you hear nothing,
> click anywhere in the editor once.
## Audio sources
Right-click the Hierarchy, then **Audio Source**. The new emitter is silent; in the
Inspector, under **Audio Source**, pick a clip and set:
| Field | Meaning |
|---|---|
| Gain | volume (0 is silent, 1 is full) |
| Pitch | playback speed |
| AttMin / AttMax | the distance where it starts to fade, and where it can't be heard any more |
| Loop | repeat forever |
| Preview | audition it while editing |
Sources are positioned in 3D and heard from the player camera. As a scene line:
```tgscene
-AudioSource:,gain,attenuationMin,attenuationMax[,loop]
```
The scene needs **AudioSystem** in its `update:` list, placed after `MoveByVelocity`, so that
moving sources are heard where they are now.
## Reverb zones
`-ReverbZone:radius[,rt60,wet,predelayMs]` gives an area its own echo: caves, halls,
bathrooms.
## Impact sounds (2D)
The **ImpactAudio2D** system plays a sound when 2D physics bodies collide hard enough.
Configure it with an `ImpactAudio2D` config block, and list it after `Physics2DStep`.
---
# Meadow Quest: a 2D RPG, overview
URL: https://wiki.trisgine.com/rpg2d/overview/
Build a top-down pixel-art RPG with a title screen, music, an NPC, combat, health, an inventory, a locked gate and a treasure chest, using only the web editor.

In **Meadow Quest** you walk a pixel-art hero around a walled meadow. A beagle follows you.
An old farmer gives you his sword. Two slimes guard the three golden coins: fight them,
watch your three hearts, and drink a potion if you must. Every pickup, swing and hit has a sound,
a quest line tells you what to do next, and losing all your hearts ends in GAME OVER. With all three coins the gate
opens, and the chest behind it wins the game. A main menu with a language picker opens the game, an
inventory bar shows what you carry, and a chiptune loop plays the whole time.

Everything happens in the browser editor, by clicking:
- painting sprites and tiles in **Pixel Art**;
- painting the meadow, its decorations and its walls in **Tilemap**;
- placing sprites, colliders, a camera and music in the **Hierarchy** and **Inspector**;
- wiring the gameplay in the **Script Editor**.
> [!IMPORTANT]
> This guide needs an editor with **2D visual scripting** and **Input Actions**: look for
> *Input Actions* in the **Windows** menu, and for nodes such as *SetVelocity2D* in the Script
> Editor. If they aren't there yet, your editor predates them and Part 4 onwards won't work
> until it updates. Every step was built and play-tested in a web editor that has them.
## What you'll learn
| Part | You learn |
|---|---|
| [1. Paint the sprites](/rpg2d/1-art/) | Pixel Art, palettes, pixel density, seamless tiles |
| [2. Paint the meadow](/rpg2d/2-map/) | Tilemaps: a tileset, layers, fill, rectangles, placing a map |
| [3. Hero & camera](/rpg2d/3-hero-and-camera/) | 2D sprites, Physics Body 2D, the 2D camera |
| [4. Move the hero](/rpg2d/4-move-the-hero/) | Script Editor, input actions, velocity |
| [5. Camera follow & walls](/rpg2d/5-camera-and-walls/) | finding other entities, clamping, invisible colliders |
| [6. Coins & the gate](/rpg2d/6-coins-and-gate/) | distance checks, global variables |
| [7. Pet, chest & victory](/rpg2d/7-pet-chest-win/) | following, a win condition |
| [8. Title screen & music](/rpg2d/8-title-and-music/) | a start screen, gating play, background music |
| [9. A farmer who talks](/rpg2d/9-npc-farmer/) | an NPC, speech bubbles that follow the story, a gift |
| [10. Combat & health](/rpg2d/10-combat-and-health/) | enemies that chase, a sword, hearts, respawning |
| [11. Inventory & potions](/rpg2d/11-inventory/) | an item bar, pickups, a healing potion |
| [12. Sound effects & triggers](/rpg2d/12-sounds-and-triggers/) | sensor colliders, OnTriggerEnter, PlayAudio |
| [13. A quest line on screen](/rpg2d/13-quest-text/) | a UI canvas, SetText and SetTextNumber |
| [14. Game over & restart](/rpg2d/14-game-over/) | freezing play, LoadScene |
| [15. A main menu](/rpg2d/15-main-menu/) | the game-menu system, UiCommand, a language picker |
| [16. Languages](/rpg2d/16-languages/) | your own localization keys, the CSV round trip |
| [What's next](/rpg2d/12-whats-next/) | where to take it, and what is still coming |
Allow 5–6 hours. Every part ends with **good practices** and the **assets** for that part, so
you can download a piece you'd rather not make yourself and carry on.
## One rule for the whole game: 16 pixels = 1 unit
Every image in Meadow Quest is drawn at **16 pixels per world unit**. A 16×16 sprite has scale
1×1; the 48×16 gate has scale 3×1; the 64×32 WIN banner has scale 4×2. Keep that ratio and
every pixel on screen is the same size. Break it and sprites look blurry or blocky next to
each other. [Part 1](/rpg2d/1-art/) explains how.
## The whole game
[meadow-quest.zip](/downloads/meadow-quest.zip) has everything: 26 images, the music and 7 sound effects,
each with its `.mt` file, the map, the HUD and menu canvas, the 19 scripts and the finished scene `MeadowQuest.tgscene`.
[Import](/editor/project-browser/#importing-files) the `.mt` files together with their images
so the UUIDs match.

[Start: paint the sprites →](/rpg2d/1-art/)
---
# 1. Paint the sprites
URL: https://wiki.trisgine.com/rpg2d/1-art/
Paint the characters, props and tiles at 16 pixels per unit with a shared palette, and save them as textures.

## What you need
| File | Size | What |
|---|---|---|
| `mq-hero.png` | 16×16 | the hero |
| `mq-pet.png` | 16×16 | the beagle |
| `mq-coin.png` | 16×16 | a coin |
| `mq-chest.png` | 16×16 | the treasure chest |
| `mq-gate.png` | 48×16 | the gate: three tiles wide |
| `mq-grass.png`, `mq-grass2.png`, `mq-flowers.png` | 16×16 | grass tiles (three variants) |
| `mq-path.png`, `mq-path-left.png`, `mq-path-right.png` | 16×16 | the path, and its two grassy edges |
| `mq-wall.png` | 16×16 | stone wall tile |
| `mq-bush.png`, `mq-rock.png` | 16×16 | decorations |
| `mq-win.png` | 64×32 | the WIN banner |
| `mq-title.png` | 96×48 | the title card |
| `mq-farmer.png`, `mq-slime.png` | 16×16 | the farmer and the slimes ([Parts 9–10](/rpg2d/9-npc-farmer/)) |
| `mq-sword.png`, `mq-potion.png` | 16×16 | items |
| `mq-heart.png` | 8×8 | a heart for the health bar (scale 0.5) |
| `mq-gameover.png` | 96×32 | the GAME OVER plaque ([Part 14](/rpg2d/14-game-over/)) |
| `mq-logo.png` | 96×48 | the menu logo ([Part 15](/rpg2d/15-main-menu/)) |
| `mq-invbar.png` | 80×16 | the five-slot inventory bar |
| `mq-bubble-hello.png`, `mq-bubble-sword.png` | 96×40 | the farmer's speech bubbles |
> [!TIP]
> Painting 26 images takes a while. Paint the hero yourself to learn the tools, then import the
> rest from [this part's assets](#this-parts-assets) and carry on.
## How to paint one
1. **Windows > Pixel Art**. It opens with a 32×32 canvas. For a 16×16 sprite, click **New**
(the first toolbar icon) and enter 16 × 16.
2. Pick a colour: drag in the big square and the rainbow strip, or type a hex value into the
field above them (for example `0099DB` for the tunic).
3. Paint with the **Pencil**. **Rectangle** (with *filled* under the tools) and **Flood fill**
are quick for blocks of colour. [ and ] change the brush size.
4. Leave the background transparent: the canvas shows a checkerboard there.
## How to save it
1. Click **Save As** (the second disk icon in the toolbar).
2. In the dialog's folder browser go to `Assets/Textures`, type the name (for example
`mq-hero`) and pick **Flattened image (.png): one merged image**.
3. Click **Save**. The status line confirms where it was saved.
## Good practices
- **Text in sprites**: the speech bubbles use a tiny 3×5 pixel font. Keep text dark on a light
background, one pixel between letters, and centre each line.
- **Keep 16 pixels per unit.** Draw a one-tile thing at 16×16, a three-tile thing at 48×16.
Later you set its scale to the size in tiles (1×1, 3×1), and every pixel matches the map's.
Never draw a sprite at 16×16 and scale it to 1.5: its pixels become 1.5 times bigger than
everyone else's.
- **Use one small palette for everything.** Meadow Quest uses colours from the free
*Endesga 32* palette. A shared palette is what makes separate sprites look like one game.
Type the hex values into the picker, or keep them in the **Recent** list.
- **Outline in a very dark colour, not pure black.** The sprites here use `181425`, a dark
purple, which looks softer than `000000`.
- **Light from the top left.** Put highlights on top-left edges and shadows bottom-right, on
every sprite. Consistent light makes the scene read as one world.
- **Make tiles seamless.** Grass and path tiles repeat edge to edge. Turn on **Tile preview** in
the toolbar to see the tile repeated and spot seams. Keep each tile's detail low and even, or
the repetition shows.
- **Several variants beat one detailed tile.** Two grass tiles and a flower tile, mixed, look
natural. One busy tile repeated looks like wallpaper.
- **Name files with a prefix** (`mq-`) so they're easy to find and don't replace another
game's textures: saving over an existing texture replaces it everywhere.
## This part's assets
All images, each with its `.mt` file (import both so the UUIDs match):
[mq-hero](/downloads/meadow-quest/mq-hero.png) ·
[mq-pet](/downloads/meadow-quest/mq-pet.png) ·
[mq-coin](/downloads/meadow-quest/mq-coin.png) ·
[mq-chest](/downloads/meadow-quest/mq-chest.png) ·
[mq-gate](/downloads/meadow-quest/mq-gate.png) ·
[mq-grass](/downloads/meadow-quest/mq-grass.png) ·
[mq-grass2](/downloads/meadow-quest/mq-grass2.png) ·
[mq-flowers](/downloads/meadow-quest/mq-flowers.png) ·
[mq-path](/downloads/meadow-quest/mq-path.png) ·
[mq-path-left](/downloads/meadow-quest/mq-path-left.png) ·
[mq-path-right](/downloads/meadow-quest/mq-path-right.png) ·
[mq-wall](/downloads/meadow-quest/mq-wall.png) ·
[mq-bush](/downloads/meadow-quest/mq-bush.png) ·
[mq-rock](/downloads/meadow-quest/mq-rock.png) ·
[mq-win](/downloads/meadow-quest/mq-win.png) ·
[mq-title](/downloads/meadow-quest/mq-title.png) ·
[mq-farmer](/downloads/meadow-quest/mq-farmer.png) ·
[mq-slime](/downloads/meadow-quest/mq-slime.png) ·
[mq-sword](/downloads/meadow-quest/mq-sword.png) ·
[mq-potion](/downloads/meadow-quest/mq-potion.png) ·
[mq-heart](/downloads/meadow-quest/mq-heart.png) ·
[mq-invbar](/downloads/meadow-quest/mq-invbar.png) ·
[mq-bubble-hello](/downloads/meadow-quest/mq-bubble-hello.png) ·
[mq-bubble-sword](/downloads/meadow-quest/mq-bubble-sword.png) ·
[mq-gameover](/downloads/meadow-quest/mq-gameover.png) ·
[mq-logo](/downloads/meadow-quest/mq-logo.png)
The `.mt` file sits next to each image: add `.mt` to the link (for example
[mq-hero.png.mt](/downloads/meadow-quest/mq-hero.png.mt)). All of them are also in
[meadow-quest.zip](/downloads/meadow-quest.zip).
[Next: paint the meadow →](/rpg2d/2-map/)
---
# 2. Paint the meadow
URL: https://wiki.trisgine.com/rpg2d/2-map/
Build a 21×21 tilemap with three layers (ground, decorations, walls) and place it in a new scene.

The map has three **layers**, drawn on top of each other:
| Layer | z | What goes on it |
|---|---|---|
| **Ground** | 0 | grass everywhere, the path down the middle |
| **Decor** | 1 | bushes and rocks |
| **Walls** | 2 | stone walls round the edge, and a fence across the middle with a 3-tile gap |
## How to create the map
1. In the **Project** panel, open `Assets/Tilemaps` (create the folder if needed),
right-click empty space and choose **Create > Tilemap**. A map called **New Tilemap**
appears. On the web editor its name can't be changed yet; that's fine, the name only
matters to you.
2. Select it and click **Open in Tilemap** in the Inspector (or double-click it).
A new map is 21 × 21 cells of 1 world unit each.
## How to add the tiles
1. Click **+ Add tile**. In the picker, type `mq` in the filter box.
2. Click each tile you need to select it: the three grass tiles, the three path tiles, the
wall, the bush and the rock. Then click **Add 9 selected**.

## How to paint the Ground layer
1. Click the plain grass tile in the **Tileset**, then the **Fill** tool (the paint bucket), and
click the grid. The whole map turns green.
2. Click the second grass tile, then the **Pencil**, and dab it onto a third of the cells,
here and there. Do the same with the flower tile on a few cells.
3. Click **path-left**, choose **Rect**, and drag a rectangle down column 10 (counting from 1),
from the top edge to the bottom. Then **path** down column 11 and **path-right** down
column 12.
> [!WARNING]
> Clicking a tile in the Tileset switches back to the Pencil. Always pick the **tile first**,
> then the tool.
## How to paint the Decor and Walls layers
1. Click **+ Layer**. A new layer appears above Ground, at z 1. Make sure it's selected (it's
highlighted) and paint a few **bushes** and **rocks** with the Pencil.
2. Click **+ Layer** again for the walls (z 2). With the **wall** tile and **Rect**, paint:
- the outer ring: the top row, the bottom row, the left column and the right column;
- the fence: row 9 from the top, from column 2 to column 9, and from column 13 to column 20.
Leave columns 10–12 empty: that's the gate's opening.
3. Click **Save**.
## How to place it in a scene
1. **File > New Scene**. It opens empty.
2. Right-click empty space in the **Hierarchy**, then **Create Empty 2D**.
3. With it selected, **Add Component > Tilemap**, and pick your map in the **Map** list.
4. The map is drawn from the entity's position as its **bottom-left corner**. To centre it on
the origin, set **Origin** to `-10.5` and `-10.5` (double-click a number field to type).
5. Rename the entity to `Meadow`: select it, press F2, type, and press
Enter.
6. Save the scene with Ctrl+S.

## Good practices
- **One job per layer.** Ground, decorations and walls on separate layers let you repaint one
without disturbing the others, and decide what draws over what.
- **Odd sizes centre nicely.** A 21-wide map has a middle column (11), so a 3-wide path and a
3-wide gate sit exactly in the centre. Origin −10.5 puts that middle on x = 0.
- **Mix variants sparingly.** About two thirds plain grass, a third of the second grass tile,
and flowers on one cell in ten.
- **Undo removes tiles too.** Undo walks back every step, including **+ Add tile**.
If your tileset empties, click **Redo**.
- **Tiles don't block anything yet.** The painted walls are only pictures; in
[Part 5](/rpg2d/5-camera-and-walls/) you put invisible colliders on top of them.
## This part's assets
[meadow.tgtilemap](/downloads/meadow-quest/meadow.tgtilemap) and its
[.mt](/downloads/meadow-quest/meadow.tgtilemap.mt), the finished map. It uses the nine tile
images from [Part 1](/rpg2d/1-art/#this-parts-assets); import those first.
[Next: hero & camera →](/rpg2d/3-hero-and-camera/)
---
# 3. Hero & camera
URL: https://wiki.trisgine.com/rpg2d/3-hero-and-camera/
Add the hero as a 2D sprite with a physics body, and a 2D camera to look through.
## How to add the hero

1. Right-click the Hierarchy, then **2D Sprite**. A white square appears.
2. Press F2 and rename it **`Hero`**, with exactly this spelling and capital H. The
scripts find it by this name.
3. In the Inspector's **Transform 2D** section:
- **Position**: `0`, `-8` (near the bottom of the path);
- **Scale**: leave it at `1`, `1`: a 16×16 image at scale 1 is exactly one tile;
- **Z-Order**: `10`, so the hero is drawn above the map;
- click the image slot (it reads `white.png`), type `hero` in the filter, and pick
`mq-hero.png`.
4. **Add Component > Physics Body 2D**. This gives the hero a box collider and a velocity, so
that walls can stop it.
5. In the **Physics 2D** section, set:
- **Half width** `0.4` and **Half height** `0.45`, a little smaller than the tile, so the
hero slips through 1-tile gaps;
- **Gravity scale** `0`, so the hero doesn't fall down the screen;
- tick **Fixed rotation**, so it doesn't spin when it bumps into things;
- tick **Never sleeps**, so a resting body still reacts to the keyboard at once.


## How to add the camera
1. Right-click the Hierarchy, then **Create Empty 2D**. Rename it **`Camera`**.
2. Set its **Position** to `0`, `-6`.
3. **Add Component > 2D Camera**. The **Simulation** panel now shows the world through it.
4. In the **2D Camera** section, set **Ortho Height** to `9`: the view is 9 tiles tall.

Press **▶ Play** to check: you see the meadow, the path and the hero. Nothing moves yet. Press
**■ Stop**, then save with Ctrl+S.
## Good practices
- **Scale = size in tiles.** With 16 px per unit, a 16×16 sprite always has scale 1×1. If a
character should be bigger, draw it bigger (32×32 at scale 2×2), don't stretch it.
- **Colliders slightly smaller than the art** make movement forgiving. Players blame the game
when a character snags on a corner it visibly cleared.
- **Top-down games need zero gravity.** A new scene has normal downward gravity and the editor
has no scene-wide gravity setting yet, so set **Gravity scale** to `0` on every Physics Body
2D.
- **Choose the camera height for the mood.** A small Ortho Height (8–10 tiles) feels close and
chunky; a big one (15+) shows more of the map and makes everything tiny. Pixel art looks
crispest when each art pixel covers a whole number of screen pixels, so try a few heights
in the Simulation panel and keep the one that looks sharpest.
- **Z-Order by role:** ground 0, decorations 1, walls 2–5, items 8, characters 9–10,
overlays such as banners 50+.
## This part's assets
[mq-hero.png](/downloads/meadow-quest/mq-hero.png) and its
[.mt](/downloads/meadow-quest/mq-hero.png.mt). The finished scene with every entity is
[MeadowQuest.tgscene](/downloads/meadow-quest/MeadowQuest.tgscene).
[Next: move the hero →](/rpg2d/4-move-the-hero/)
---
# 4. Move the hero
URL: https://wiki.trisgine.com/rpg2d/4-move-the-hero/
Your first 2D visual script. Read the Move action (WASD, arrows, gamepad) and turn it into the hero's velocity.
## The idea
Every frame: read the **Move** input as a direction, multiply it by a speed, and use it as
the hero's velocity. The physics engine then moves the hero, and stops it at walls.
```text
OnUpdate ──▶ SetVelocity2D( MakeVec2( x , y ) )
x, y = Vec3X / Vec3Y of ScaleVec3( ActionVector2 "Move" , 5 )
```
**Move** is a built-in *input action*. Out of the box it is bound to W A
S D, the arrow keys and a gamepad's left stick. You can see and change
the bindings in **Windows > Input Actions**.
> [!NOTE]
> `ActionVector2` hands you a 3-component vector (x, y and 0), while the 2D nodes want a
> 2-component one. That's why the graph splits it with **Vec3X** / **Vec3Y** and rebuilds it
> with **MakeVec2**. Wires only connect between matching pin types.
## Build it
1. **Windows > Script Editor**, then **+ New**. Type `HeroMove` and press **Create**.
2. The new script starts with a demo graph made for 3D objects. Click each node *except*
**OnUpdate** and press Delete.
3. Add nodes: hover over an empty part of the canvas, press Space, type part of the
name, and press Enter. The node appears under the mouse. Add:
**ActionVector2**, **ConstNumber**, **ScaleVec3**, **Vec3X**, **Vec3Y**, **MakeVec2**,
**SetVelocity2D**.
4. Click the **ConstNumber** node. The strip above the canvas shows its value; set it to `5`
(the speed). **ActionVector2** already says `action = Move`.
5. Wire it by dragging from an output pin (right side of a node) to an input pin (left side):
- **OnUpdate**'s white *exec* pin → **SetVelocity2D**'s exec input
- **ActionVector2** → **ScaleVec3** `v`; **ConstNumber** → **ScaleVec3** `s`
- **ScaleVec3** → **Vec3X** and → **Vec3Y**
- **Vec3X** → **MakeVec2** `x`; **Vec3Y** → **MakeVec2** `y`
- **MakeVec2** → **SetVelocity2D** `value`
6. **Compile**. The status should read *compiles (1 handler)*. Then **Save**.

If something is missing, the editor says so plainly. For example, an action that isn't
connected to an event reads *"sits in an exec chain no event handler reaches… wire it to
OnStart or OnUpdate"*.
### …or paste the text
Switch to the **Text** tab, select everything, and paste. The graph rebuilds itself:
```tgscript
//!tgscript v1
//! script name=HeroMove
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 ActionVector2 pos=(260,80) action=Move
const n2_value = ctx.actionVector2("Move");
//! node 3 ConstNumber pos=(260,200)
const n3_value = 5.00;
//! node 4 ScaleVec3 pos=(460,120)
const n4_out = ctx.scaleVec3(n2_value, n3_value);
//! node 5 Vec3X pos=(660,80)
const n5_out = ctx.vec3X(n4_out);
//! node 6 Vec3Y pos=(660,200)
const n6_out = ctx.vec3Y(n4_out);
//! node 7 MakeVec2 pos=(860,120)
const n7_out = ctx.makeVec2(n5_out, n6_out);
//! node 8 SetVelocity2D pos=(1060,120)
ctx.setVelocity2D(n7_out);
}
//! endregion
```
## Attach and play
1. Select **Hero**. In the Inspector's **Script** section, click the slot that reads *(none)*
and pick `HeroMove.tgscript`.
2. **▶ Play**, click into the **Simulation** panel, and walk with W A
S D. The hero moves at 5 units per second and stops when you let go.
3. **■ Stop** puts the hero back where it started.
In our test, holding D for about a second moved the hero 4.6 units right, and it
didn't drift down. That's the zero gravity scale from Part 3 doing its job.
## Good practices
- **Keep tuning numbers in one node.** The speed lives in a single **ConstNumber**; change it
there and nothing else. Name things so a graph reads left to right: input → maths → action.
- **Drive physics bodies with velocity, not position.** Setting the velocity lets the physics
engine stop the hero at walls. Setting the position teleports it through them.
- **Read actions, not keys.** **Move** already covers WASD, the arrows and a gamepad, and the
bindings can change in **Windows > Input Actions** without touching the script.
- **Compile often.** The status line names the node that's wrong, in plain words.
## This part's assets
[HeroMove.tgscript](/downloads/meadow-quest/HeroMove.tgscript). The download is the final
version from [Part 8](/rpg2d/8-title-and-music/), which also waits for the title screen; the
text above is this part's version.
[Next: camera follow & walls →](/rpg2d/5-camera-and-walls/)
---
# 5. Camera follow & walls
URL: https://wiki.trisgine.com/rpg2d/5-camera-and-walls/
Make the camera follow the hero without showing past the map's edge, and put invisible colliders on the painted walls.
## How to make the camera follow
A script on the **camera** looks up the hero by name every frame and moves to it, but
**clamps** the position so the view never shows past the edge of the map.
```text
OnUpdate ──▶ SetPosition2D( MakeVec2( Clamp(hero.x, −2.5, 2.5) , Clamp(hero.y, −6, 6) ) )
```

1. **Script Editor > + New**, then `CameraFollow`. Delete the demo nodes except **OnUpdate**.
2. Add **FindEntity** and set its `entity` to `Hero` in the strip above the canvas.
3. Add **GetEntityPosition2D**, **Vec2X**, **Vec2Y**, two **Clamp** nodes, four
**ConstNumber** nodes (`-2.5`, `2.5`, `-6`, `6`), **MakeVec2** and **SetPosition2D**.
4. Wire **FindEntity → GetEntityPosition2D → Vec2X** and **→ Vec2Y**; Vec2X into the first
Clamp's `value` with `-2.5` / `2.5` as `min` / `max`; Vec2Y into the second with `-6` / `6`;
both Clamps into **MakeVec2** `x` / `y`; MakeVec2 into **SetPosition2D** `value`; and
**OnUpdate**'s exec into **SetPosition2D**.
5. **Compile**, **Save**, then select **Camera** and pick `CameraFollow.tgscript` in its
**Script** slot.
Text version:
```tgscript
//!tgscript v1
//! script name=CameraFollow
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,220) entity=Hero
const n2_value = ctx.findEntity("Hero");
//! node 3 GetEntityPosition2D pos=(260,220)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 Vec2X pos=(460,160)
const n4_out = ctx.vec2X(n3_value);
//! node 5 Vec2Y pos=(460,300)
const n5_out = ctx.vec2Y(n3_value);
//! node 6 ConstNumber pos=(460,420)
const n6_value = -2.50;
//! node 7 ConstNumber pos=(460,520)
const n7_value = 2.50;
//! node 8 Clamp pos=(660,160)
const n8_out = ctx.clamp(n4_out, n6_value, n7_value);
//! node 9 ConstNumber pos=(460,620)
const n9_value = -6.00;
//! node 10 ConstNumber pos=(460,720)
const n10_value = 6.00;
//! node 11 Clamp pos=(660,320)
const n11_out = ctx.clamp(n5_out, n9_value, n10_value);
//! node 12 MakeVec2 pos=(860,220)
const n12_out = ctx.makeVec2(n8_out, n11_out);
//! node 13 SetPosition2D pos=(1060,80)
ctx.setPosition2D(n12_out);
}
//! endregion
```
> [!TIP]
> Where do −6 and 6 come from? The map reaches 10.5 units from the centre and the view is 9
> tall (4.5 each way), so the camera can go 10.5 − 4.5 = 6 up or down. Sideways, a 16:9 window
> shows 16 units, so 10.5 − 8 = 2.5. Change the Ortho Height and these numbers change with it.
## How to make the walls solid
The walls are painted on the tilemap's **Walls** layer with the `mq-wall` tile. Mark that tile as
**solid** and every cell painted with it blocks Physics 2D bodies, such as the hero.
1. **Windows > Tilemap**, **Open…**, and pick `meadow.tgtilemap`.
2. In the **Tileset**, right-click the wall tile and tick **Solid (blocks Physics 2D)**. A small
badge appears on the tile.
3. **Save** the tilemap.

**Play** and walk into a wall: the hero stops, flush against the stones. Neighbouring solid cells
are merged into a few long boxes behind the scenes, so the hero slides smoothly along a wall.
> [!IMPORTANT]
> This part needs an editor from **18 October 2026 or later**. Right-click a tile in the Tileset: the menu should offer **Solid (blocks Physics 2D)**. If it doesn't, your editor
> predates the feature; it arrives with the next editor update.
### Older editors: invisible colliders
Without the Solid option, put an **invisible collider** on top of each wall: a 2D Sprite with a
Collider 2D, made see-through.
| Name | Position | Scale |
|---|---|---|
| `WallLeft` | −6, 2 | 9, 1 |
| `WallRight` | 6, 2 | 9, 1 |
| `WallSouth` | 0, −10 | 21, 1 |
| `WallNorth` | 0, 10 | 21, 1 |
| `WallWest` | −10, 0 | 1, 19 |
| `WallEast` | 10, 0 | 1, 19 |
For each one:
1. Right-click the Hierarchy, then **2D Sprite**. Rename it (F2), set **Position** and
**Scale** from the table.
2. In **Tint**, double-click the **A** (alpha) field, type `0` and press Enter. The
sprite disappears; the painted wall shows through.
3. **Add Component > Collider 2D**, then in **Physics 2D** click **Fit to sprite**. **Half
width** and **Half height** become half the scale (for `WallLeft`, `4.5` and `0.5`).

Make one wall, then right-click it and **Duplicate** for the others. When your editor gains
**Solid** tiles, delete these six and mark the tile solid instead.
## Good practices
- **Collision follows the tiles.** With a solid wall tile, repainting a wall moves its collision
too; there is nothing to keep in step by hand.
- **Only walls are solid.** Grass, path and decorations stay walkable. A rock on the Decor layer
could block too: mark the rock tile solid, and only the rock's cells block.
- **Fewer, bigger colliders.** The engine merges solid cells into long boxes; if you place
colliders by hand, one 9×1 box is cheaper and smoother to slide along than nine 1×1 boxes.
- **A collider without a Physics Body is static.** The Inspector says so ("this collider is
STATIC"): walls never move, only dynamic bodies such as the hero bump into them.
- **Clamp the camera.** Never let the player see the empty space past the edge of the map.
- **Find by name, carefully.** `FindEntity` matches the Hierarchy name exactly. If the camera
doesn't move, check that the hero is called `Hero`.
## This part's assets
[CameraFollow.tgscript](/downloads/meadow-quest/CameraFollow.tgscript) ·
[meadow.tgtilemap](/downloads/meadow-quest/meadow.tgtilemap). The downloads load in every editor, so the
wall tile isn't marked solid there and the scene keeps the six invisible walls; on a newer editor,
mark the tile solid and delete them.
[Next: coins & the gate →](/rpg2d/6-coins-and-gate/)
---
# 6. Coins & the gate
URL: https://wiki.trisgine.com/rpg2d/6-coins-and-gate/
Coins that count themselves into a global variable, and a gate that opens on the third one.
## The coin
Each coin checks how far away the hero is. Within 0.8 units it adds 1 to a **global variable**
called `coins` (shared by every script), then moves itself far off-screen.
```text
OnUpdate ─▶ Branch( Vec2Distance( hero position , my position ) < 0.8 )
then ─▶ SetGlobal coins = GetGlobal coins + 1
─▶ SetPosition2D( 200 , 200 )
```
> [!TIP]
> Every project already has an engine sample script called `Coin`, so this one is `MeadowCoin`.
> Did the 3D tutorial in the same project? It has a `Gate` too: name this one `MeadowGate`.
1. **Script Editor > + New**, then `MeadowCoin`. Keep **OnUpdate** and delete the rest.
2. Build the graph above with these nodes: **FindEntity** (`entity` = `Hero`),
**GetEntityPosition2D**, **GetPosition2D**, **Vec2Distance**, **ConstNumber** (`0.8`),
**Less**, **Branch**, **GetGlobal** (`global` = `coins`), **ConstNumber** (`1`),
**AddNumber**, **SetGlobal** (`global` = `coins`), **ConstVec2** (`200`, `200`),
**SetPosition2D**.
- Exec wires: **OnUpdate → Branch**, then Branch **then → SetGlobal → SetPosition2D**.
3. **Compile**, **Save**.

Or paste the text:
```tgscript
//!tgscript v1
//! script name=MeadowCoin
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(260,80) entity=Hero
const n2_value = ctx.findEntity("Hero");
//! node 3 GetEntityPosition2D pos=(460,80)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 GetPosition2D pos=(460,200)
const n4_value = ctx.getPosition2D();
//! node 5 Vec2Distance pos=(660,120)
const n5_out = ctx.vec2Distance(n3_value, n4_value);
//! node 6 ConstNumber pos=(660,240)
const n6_value = 0.80;
//! node 7 Less pos=(860,120)
const n7_out = (n5_out < n6_value);
//! node 8 Branch pos=(1060,80)
if (n7_out) {
//! node 9 GetGlobal pos=(1060,240) global=coins
const n9_value = ctx.getGlobal("coins");
//! node 10 ConstNumber pos=(1060,340)
const n10_value = 1.00;
//! node 11 AddNumber pos=(1260,280)
const n11_out = (n9_value + n10_value);
//! node 12 SetGlobal pos=(1460,240) global=coins
ctx.setGlobal("coins", n11_out);
//! node 13 ConstVec2 pos=(1260,80)
const n13_value = ctx.vec2(200.00, 200.00);
//! node 14 SetPosition2D pos=(1460,80)
ctx.setPosition2D(n13_value);
}
}
//! endregion
```
Now place three coins, south of the fence: 2D Sprites named `Coin1`–`Coin3` with image `mq-coin`,
scale 1×1, **Z-Order** `8`, at **(0, −5)**, **(−6, −3)** and **(6, −6)**, each with
`MeadowCoin.tgscript` in its **Script** slot. One script serves all three.
> [!NOTE]
> Coins have **no collider** yet: the script's distance check is the pickup.
> [Part 12](/rpg2d/12-sounds-and-triggers/) turns them into triggers that react the moment the
> hero touches them.
## The gate
The gate is a wall that moves out of the way once `coins` reaches 3.
1. A 2D Sprite named `Gate`: image `mq-gate`, **Position** (0, 2), **Scale** (3, 1), **Z-Order** `5`,
plus **Add Component > Collider 2D** (**Fit to sprite**: half size 1.5 × 0.5). It fills the
3-tile gap in the fence. The image is 48×16, so scale 3×1 keeps it at 16 px per unit.
2. Script `Gate`:
```tgscript
//!tgscript v1
//! script name=Gate
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetGlobal pos=(260,120) global=coins
const n2_value = ctx.getGlobal("coins");
//! node 3 ConstNumber pos=(260,240)
const n3_value = 3.00;
//! node 4 GreaterEqual pos=(460,120)
const n4_out = (n2_value >= n3_value);
//! node 5 Branch pos=(660,80)
if (n4_out) {
//! node 6 ConstVec2 pos=(660,240)
const n6_value = ctx.vec2(200.00, 210.00);
//! node 7 SetPosition2D pos=(860,80)
ctx.setPosition2D(n6_value);
}
}
//! endregion
```

Attach it to **Gate**.
## Play-test
- Walk north before collecting the coins: the closed gate blocks you, just like the fence.
- Collect all three: on the third, the gate disappears, and its collider goes with it.
- **Stop** resets everything, including the `coins` counter.

## Good practices
- **One script, many objects.** All three coins share `MeadowCoin.tgscript`: fix it once, every coin
gets the fix. Each coin acts on itself, because `GetPosition2D` and `SetPosition2D` without an
entity mean "me".
- **Globals for game state.** `coins` and later `won` are shared by every script and reset when
you press **Stop**. Use clear names; a typo makes a second, empty variable.
- **Moving far away** is today's way to remove something (spawn and destroy are coming). Pick a
spot no camera can reach, like (200, 200).
- **Distance checks are fine to start with.** [Part 12](/rpg2d/12-sounds-and-triggers/) shows
the better tool for pickups: a trigger.
## This part's assets
[MeadowCoin.tgscript](/downloads/meadow-quest/MeadowCoin.tgscript) ·
[Gate.tgscript](/downloads/meadow-quest/Gate.tgscript) ·
[mq-coin.png](/downloads/meadow-quest/mq-coin.png) ·
[mq-gate.png](/downloads/meadow-quest/mq-gate.png) (each image with its `.mt`). The two scripts
are the finished versions from [Part 12](/rpg2d/12-sounds-and-triggers/), with triggers and sounds.
[Next: pet, chest & victory →](/rpg2d/7-pet-chest-win/)
---
# 7. Pet, chest & victory
URL: https://wiki.trisgine.com/rpg2d/7-pet-chest-win/
A dog that follows the hero, a treasure chest, and a WIN banner.
## The pet
The dog **sets its velocity** toward the hero every frame, but only while it is more than 1.5
units away, so it trots behind you instead of sitting on your head. The engine's
**MoveByVelocity2D** system then moves it, exactly as it moves everything else.
```text
offset = hero - me
if length(offset) > 1.5: velocity = normalize(offset) x 3.5 else: velocity = 0
```
1. Create a 2D Sprite `Pet` (image `mq-pet`, **Z-Order** `9`, at (2, -9)).
2. **Add Component > Velocity x,y**. Now the sprite has a velocity for scripts to set and the
engine to apply. No physics body is needed: it walks through walls, as pets do.
3. Give it this script:

```tgscript
//!tgscript v1
//! script name=Pet
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,220) entity=Hero
const n2_value = ctx.findEntity("Hero");
//! node 3 GetEntityPosition2D pos=(260,220)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 GetPosition2D pos=(260,340)
const n4_value = ctx.getPosition2D();
//! node 5 SubVec2 pos=(460,260)
const n5_out = ctx.subVec2(n3_value, n4_value);
//! node 6 Vec2Length pos=(660,340)
const n6_out = ctx.vec2Length(n5_out);
//! node 7 ConstNumber pos=(660,440)
const n7_value = 1.50;
//! node 8 Greater pos=(860,340)
const n8_out = (n6_out > n7_value);
//! node 9 Branch pos=(1060,80)
if (n8_out) {
//! node 10 Vec2Normalize pos=(660,180)
const n10_out = ctx.vec2Normalize(n5_out);
//! node 11 ConstNumber pos=(860,180)
const n11_value = 3.50;
//! node 12 ScaleVec2 pos=(1060,200)
const n12_out = ctx.scaleVec2(n10_out, n11_value);
//! node 13 SetVelocity2D pos=(1260,80)
ctx.setVelocity2D(n12_out);
} else {
//! node 14 ConstVec2 pos=(1060,320)
const n14_value = ctx.vec2(0.00, 0.00);
//! node 15 SetVelocity2D pos=(1260,240)
ctx.setVelocity2D(n14_value);
}
}
//! endregion
```
> [!TIP]
> Why velocity and not position? A script that writes the position does the engine's job
> badly: it must multiply by **DeltaTime** itself, it skips collisions, and other systems don't
> know the object moved. Set the velocity and let the engine integrate it. See
> [scripting best practices](/logic/best-practices/).
## The chest
A 2D Sprite `Chest` (image `mq-chest`, scale 1 × 1, **Z-Order** `8`) at (0, 6), north of the
gate. When the hero comes within 1 unit, it sets a global `won` to 1:
```tgscript
//!tgscript v1
//! script name=Chest
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(260,80) entity=Hero
const n2_value = ctx.findEntity("Hero");
//! node 3 GetEntityPosition2D pos=(460,80)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 GetPosition2D pos=(460,200)
const n4_value = ctx.getPosition2D();
//! node 5 Vec2Distance pos=(660,120)
const n5_out = ctx.vec2Distance(n3_value, n4_value);
//! node 6 ConstNumber pos=(660,240)
const n6_value = 1.00;
//! node 7 Less pos=(860,120)
const n7_out = (n5_out < n6_value);
//! node 8 Branch pos=(1060,80)
if (n7_out) {
//! node 9 ConstNumber pos=(1060,240)
const n9_value = 1.00;
//! node 10 SetGlobal pos=(1260,80) global=won
ctx.setGlobal("won", n9_value);
}
}
//! endregion
```
## The WIN banner
A 2D Sprite `WinBanner` (image `mq-win`, **Scale** 4 × 2, since the image is 64×32 pixels,
**Z-Order** `50`), parked far away at (200, 220). Once `won` is set, it moves to the camera,
just above the middle of the view:
```tgscript
//!tgscript v1
//! script name=WinBanner
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetGlobal pos=(260,120) global=won
const n2_value = ctx.getGlobal("won");
//! node 3 ConstNumber pos=(260,240)
const n3_value = 0.50;
//! node 4 Greater pos=(460,120)
const n4_out = (n2_value > n3_value);
//! node 5 Branch pos=(660,80)
if (n4_out) {
//! node 6 FindEntity pos=(660,240) entity=Camera
const n6_value = ctx.findEntity("Camera");
//! node 7 GetEntityPosition2D pos=(860,240)
const n7_value = ctx.getEntityPosition2D(n6_value);
//! node 8 ConstVec2 pos=(860,360)
const n8_value = ctx.vec2(0.00, 1.00);
//! node 9 AddVec2 pos=(1060,240)
const n9_out = ctx.addVec2(n7_value, n8_value);
//! node 10 SetPosition2D pos=(1260,80)
ctx.setPosition2D(n9_out);
}
}
//! endregion
```
## Play the whole game

**▶ Play**: collect the three coins, walk through the opened gate, reach the chest, and you
get **WIN**. **■ Stop** and play again: everything resets.
Save with Ctrl+S. You've made a complete little 2D game in the browser.
## Good practices
- **Followers need a stop distance.** Without the "only if farther than 1.5" check, the dog would
sit on the hero and jitter.
- **Move with velocity.** Set a speed in units per second; the engine applies it every frame at
the right rate, so you never multiply by DeltaTime yourself.
- **Show UI where the player looks.** The banner positions itself on the **camera**, not at a
fixed spot in the world, so it is always on screen.
- **One win flag** (`won`) that several scripts read keeps the logic easy to follow.
## This part's assets
[Pet.tgscript](/downloads/meadow-quest/Pet.tgscript) ·
[Chest.tgscript](/downloads/meadow-quest/Chest.tgscript) ·
[WinBanner.tgscript](/downloads/meadow-quest/WinBanner.tgscript) ·
[mq-pet.png](/downloads/meadow-quest/mq-pet.png) ·
[mq-chest.png](/downloads/meadow-quest/mq-chest.png) ·
[mq-win.png](/downloads/meadow-quest/mq-win.png) (each image with its `.mt`).
[Next: title screen & music →](/rpg2d/8-title-and-music/)
---
# 8. Title screen & music
URL: https://wiki.trisgine.com/rpg2d/8-title-and-music/
A title card that waits for Space before the hero can move, and a chiptune loop playing in the background.

## How the title screen works
There's no menu system to set up: the title is a **sprite** with a small script, and a global
variable `started` that is 0 until the player presses Space.
```text
while started < 0.5: title sits on the camera; if Jump pressed: started = 1, title moves away
HeroMove: speed = 5 × started (0 until the game starts)
```
**Jump** is a built-in action bound to Space and a gamepad's bottom button.
## How to add the title card
1. Right-click the Hierarchy, then **2D Sprite**. Rename it `Title`.
2. Image `mq-title`, **Scale** `6`, `3` (the image is 96×48 pixels: 6×3 tiles), **Z-Order** `60`
so it covers everything.
3. **Script Editor > + New**, `TitleScreen`, and build (or paste) this graph:

```tgscript
//!tgscript v1
//! script name=TitleScreen
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetGlobal pos=(260,120) global=started
const n2_value = ctx.getGlobal("started");
//! node 3 ConstNumber pos=(260,240)
const n3_value = 0.50;
//! node 4 Less pos=(460,120)
const n4_out = (n2_value < n3_value);
//! node 5 Branch pos=(660,80)
if (n4_out) {
//! node 6 FindEntity pos=(660,260) entity=Camera
const n6_value = ctx.findEntity("Camera");
//! node 7 GetEntityPosition2D pos=(860,260)
const n7_value = ctx.getEntityPosition2D(n6_value);
//! node 8 SetPosition2D pos=(1060,80)
ctx.setPosition2D(n7_value);
//! node 9 ActionPressed pos=(1060,260) action=Jump
const n9_value = ctx.actionPressed("Jump");
//! node 10 Branch pos=(1260,80)
if (n9_value) {
//! node 11 ConstNumber pos=(1260,260)
const n11_value = 1.00;
//! node 12 SetGlobal pos=(1460,80) global=started
ctx.setGlobal("started", n11_value);
//! node 13 ConstVec2 pos=(1460,260)
const n13_value = ctx.vec2(200.00, 240.00);
//! node 14 SetPosition2D pos=(1660,80)
ctx.setPosition2D(n13_value);
}
}
}
//! endregion
```
4. **Compile**, **Save**, and pick `TitleScreen.tgscript` in the Title's **Script** slot.

## How to hold the hero until the game starts
Open **HeroMove** from Part 4 and make the speed depend on `started`:
1. Add **GetGlobal** (`global` = `started`) and **MulNumber**.
2. Wire the speed **ConstNumber** (5) and **GetGlobal** into **MulNumber**, and **MulNumber**
into **ScaleVec3** `s` (where the ConstNumber used to go).
3. **Compile**, **Save**.
```tgscript
//!tgscript v1
//! script name=HeroMove
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 ActionVector2 pos=(260,80) action=Move
const n2_value = ctx.actionVector2("Move");
//! node 3 ConstNumber pos=(60,200)
const n3_value = 5.00;
//! node 9 GetGlobal pos=(60,320) global=started
const n9_value = ctx.getGlobal("started");
//! node 10 MulNumber pos=(260,240)
const n10_out = (n3_value * n9_value);
//! node 4 ScaleVec3 pos=(460,120)
const n4_out = ctx.scaleVec3(n2_value, n10_out);
//! node 5 Vec3X pos=(660,80)
const n5_out = ctx.vec3X(n4_out);
//! node 6 Vec3Y pos=(660,200)
const n6_out = ctx.vec3Y(n4_out);
//! node 7 MakeVec2 pos=(860,120)
const n7_out = ctx.makeVec2(n5_out, n6_out);
//! node 8 SetVelocity2D pos=(1060,120)
ctx.setVelocity2D(n7_out);
}
//! endregion
```
**Play**: the title waits over the meadow, the hero can't move. Press Space: the
title is gone, and the game is on. **Stop** resets `started`, so the title is back next time.
## How to add music
1. [Import](/editor/project-browser/#importing-files) a music file (`.wav`, `.ogg`, `.mp3` or
`.flac`). This guide's loop is [mq-music.wav](/downloads/meadow-quest/mq-music.wav).
2. Right-click the Hierarchy, then **Audio Source**. Rename it `Music`. The editor adds the
audio system to the scene by itself.
3. In the **Audio Source** section, click **Choose clip…** and pick your file.
4. Set **Gain** `0.5`, **Att Min** `100` and **Att Max** `200`. **Autoplay** and **Loop** are
already ticked.
5. **Play**. Browsers keep sound off until you click or press a key on the page, so click into
the Simulation panel once if you hear nothing.

> [!NOTE]
> Every Audio Source is *positional*: it gets quieter with distance from the listener. Music
> should sound the same everywhere, so **Att Min** is set far larger than the map (100 units):
> within that distance, nothing fades.
## Good practices
- **Gate gameplay on one flag.** Everything that should wait (the hero now; enemies later)
multiplies or branches on `started`. One flag, one place to look.
- **Keep the title on the camera,** like the WIN banner, so it's centred whatever the camera
does.
- **Music at about half volume.** **Gain** `0.5` leaves room for sound effects later. Players
turn music down far more often than up.
- **Loop cleanly.** A loop should end on the beat it starts on; the editor's clip **Preview** in
the Inspector lets you listen to the join.
- **Mind the licence.** Use music you made, or music whose licence allows games (for example
CC0 from OpenGameArt). Keep a note of where each file came from.
- **Sound effects** (a coin chime, a gate creak) are Audio Sources that a script starts with
**PlayAudio**; [Part 12](/rpg2d/12-sounds-and-triggers/) adds them.
## This part's assets
[mq-title.png](/downloads/meadow-quest/mq-title.png) ·
[TitleScreen.tgscript](/downloads/meadow-quest/TitleScreen.tgscript) ·
[HeroMove.tgscript](/downloads/meadow-quest/HeroMove.tgscript) (the version above) ·
[mq-music.wav](/downloads/meadow-quest/mq-music.wav), each with its `.mt`. The music is a
16-second chiptune loop made for this guide; use it in your own games freely.
[Next: a farmer who talks →](/rpg2d/9-npc-farmer/)
---
# 9. A farmer who talks
URL: https://wiki.trisgine.com/rpg2d/9-npc-farmer/
An NPC with speech bubbles that change with the story, and a gift the player gets by pressing Space.

The old farmer stands near the start. Walk up to him and a speech bubble appears. Press
Space and he gives you his sword; after that his bubble says so. Walk away and the
bubble disappears.
## How it works
The bubbles are two **sprites** (text painted into the image) that the farmer's script moves
next to him or parks out of sight. Which one shows depends on a global, `hasSword`:
```text
near = distance(hero, me) < 1.8
near and no sword: show "HELLO" bubble; if Space pressed: hasSword = 1
near and has sword: show "TAKE MY SWORD" bubble
otherwise: park both bubbles
```
## How to build it
1. A 2D Sprite `Farmer` (image `mq-farmer`, **Z-Order** `9`) at (-2.5, -8.5).
2. Two 2D Sprites `BubbleHello` and `BubbleSword` (images `mq-bubble-hello` and
`mq-bubble-sword`), **Scale** `6`, `2.5` (the images are 96×40 pixels), **Z-Order** `80`,
parked at (200, 240).
3. **Script Editor > + New**, `Farmer`, paste this, **Compile**, **Save**, and put it in the
Farmer's **Script** slot:
```tgscript
//!tgscript v1
//! script name=Farmer
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,240) entity=Hero
const n2_value = ctx.findEntity("Hero");
//! node 3 GetEntityPosition2D pos=(260,240)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 GetPosition2D pos=(260,360)
const n4_value = ctx.getPosition2D();
//! node 5 Vec2Distance pos=(460,300)
const n5_out = ctx.vec2Distance(n3_value, n4_value);
//! node 6 ConstNumber pos=(460,420)
const n6_value = 1.80;
//! node 7 Less pos=(660,300)
const n7_out = (n5_out < n6_value);
//! node 8 GetGlobal pos=(460,540) global=hasSword
const n8_value = ctx.getGlobal("hasSword");
//! node 9 ConstNumber pos=(460,640)
const n9_value = 0.50;
//! node 10 Less pos=(660,540)
const n10_out = (n8_value < n9_value);
//! node 11 And pos=(860,360)
const n11_out = (n7_out && n10_out);
//! node 12 Not pos=(860,540)
const n12_out = (!n10_out);
//! node 13 And pos=(1060,480)
const n13_out = (n7_out && n12_out);
//! node 14 FindEntity pos=(860,700) entity=BubbleHello
const n14_value = ctx.findEntity("BubbleHello");
//! node 15 FindEntity pos=(860,800) entity=BubbleSword
const n15_value = ctx.findEntity("BubbleSword");
//! node 16 ConstVec2 pos=(460,760)
const n16_value = ctx.vec2(2.20, 1.90);
//! node 17 AddVec2 pos=(660,700)
const n17_out = ctx.addVec2(n4_value, n16_value);
//! node 18 ConstVec2 pos=(660,860)
const n18_value = ctx.vec2(200.00, 240.00);
//! node 19 Branch pos=(1260,80)
if (n11_out) {
//! node 20 SetEntityPosition2D pos=(1460,80)
ctx.setEntityPosition2D(n14_value, n17_out);
//! node 21 ActionPressed pos=(1460,240) action=Jump
const n21_value = ctx.actionPressed("Jump");
//! node 22 Branch pos=(1660,80)
if (n21_value) {
//! node 23 ConstNumber pos=(1660,240)
const n23_value = 1.00;
//! node 24 SetGlobal pos=(1860,80) global=hasSword
ctx.setGlobal("hasSword", n23_value);
}
} else {
//! node 25 SetEntityPosition2D pos=(1460,320)
ctx.setEntityPosition2D(n14_value, n18_value);
}
//! node 26 Branch pos=(2060,80)
if (n13_out) {
//! node 27 SetEntityPosition2D pos=(2260,80)
ctx.setEntityPosition2D(n15_value, n17_out);
} else {
//! node 28 SetEntityPosition2D pos=(2260,240)
ctx.setEntityPosition2D(n15_value, n18_value);
}
}
//! endregion
```
**Play**, press Space to start, and walk left to the farmer.
## Good practices
- **State lives in globals; pictures follow the state.** The farmer doesn't remember what he
said: he looks at `hasSword` every frame and shows the bubble that matches. Nothing can get
out of step.
- **Every branch has an `else`.** Each bubble is either placed or parked on every frame, so it
can never be left floating where it was.
- **Offsets point the tail at the speaker.** The bubble's tail is near its left edge, so the
bubble sits 2.2 units to the right of the farmer.
- **Text in sprites can't be translated.** For a game in several languages, use UI Text with
[localized](/logic/localization/) keys instead; a script's **SetText** can show a key such as
`@dlg.hello` ([Part 13](/rpg2d/13-quest-text/) uses SetText for the quest line).
## This part's assets
[Farmer.tgscript](/downloads/meadow-quest/Farmer.tgscript) ·
[mq-farmer.png](/downloads/meadow-quest/mq-farmer.png) ·
[mq-bubble-hello.png](/downloads/meadow-quest/mq-bubble-hello.png) ·
[mq-bubble-sword.png](/downloads/meadow-quest/mq-bubble-sword.png) (each image with its `.mt`).
[Next: combat & health →](/rpg2d/10-combat-and-health/)
---
# 10. Combat & health
URL: https://wiki.trisgine.com/rpg2d/10-combat-and-health/
Slimes that chase you, a sword to swing, three hearts, a moment of invulnerability after a hit, and respawning.

## The rules
- Two **slimes** guard the coins. Within 4 units of the hero they chase it.
- Touching a slime costs a **heart** and knocks the hero back. For one second after, the hero
can't be hurt again.
- With the sword, Space **swings** it in the direction you last moved. A slime within
1.5 units of the swing is defeated.
- At zero hearts the hero **respawns** at the start with three hearts. (In
[Part 14](/rpg2d/14-game-over/) this becomes a proper *game over*.)
Shared state lives in globals: `hp` (hearts left), `hurtUntil` (the time the hero can be hurt
again), `hasSword`, and `slain`.
## How to add the slimes
For each of `Slime1` at (-4, -3.5) and `Slime2` at (4.5, -4.5):
1. A 2D Sprite, image `mq-slime`, **Z-Order** `9`.
2. **Add Component > Physics Body 2D**: **Gravity scale** `0`, tick **Fixed rotation** and
**Never sleeps**, collider **Half width** `0.4`, **Half height** `0.35`. Slimes are physics
bodies, so walls stop them and they shove the hero.
3. Script `Slime`:
```tgscript
//!tgscript v1
//! script name=Slime
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,240) entity=Hero
const n2_value = ctx.findEntity("Hero");
//! node 3 GetEntityPosition2D pos=(260,240)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 GetPosition2D pos=(260,360)
const n4_value = ctx.getPosition2D();
//! node 5 SubVec2 pos=(460,300)
const n5_out = ctx.subVec2(n3_value, n4_value);
//! node 6 Vec2Length pos=(660,300)
const n6_out = ctx.vec2Length(n5_out);
//! node 7 Vec2Normalize pos=(660,420)
const n7_out = ctx.vec2Normalize(n5_out);
//! node 8 ConstNumber pos=(660,540)
const n8_value = 4.00;
//! node 9 Less pos=(860,300)
const n9_out = (n6_out < n8_value);
//! node 10 GetGlobal pos=(660,640) global=started
const n10_value = ctx.getGlobal("started");
//! node 11 ConstNumber pos=(660,740)
const n11_value = 0.50;
//! node 12 Greater pos=(860,420)
const n12_out = (n10_value > n11_value);
//! node 13 And pos=(1060,300)
const n13_out = (n9_out && n12_out);
//! node 29 ConstNumber pos=(860,840)
const n29_value = 1.00;
//! node 36 Time pos=(860,940)
const n36_value = ctx.time();
//! node 14 Branch pos=(1260,80)
if (n13_out) {
//! node 15 ConstNumber pos=(1060,420)
const n15_value = 1.80;
//! node 16 ScaleVec2 pos=(1260,320)
const n16_out = ctx.scaleVec2(n7_out, n15_value);
//! node 17 SetVelocity2D pos=(1460,80)
ctx.setVelocity2D(n16_out);
} else {
//! node 18 ConstVec2 pos=(1260,460)
const n18_value = ctx.vec2(0.00, 0.00);
//! node 19 SetVelocity2D pos=(1460,240)
ctx.setVelocity2D(n18_value);
}
//! node 20 ActionPressed pos=(1060,560) action=Jump
const n20_value = ctx.actionPressed("Jump");
//! node 21 GetGlobal pos=(1060,660) global=hasSword
const n21_value = ctx.getGlobal("hasSword");
//! node 22 Greater pos=(1260,620)
const n22_out = (n21_value > n11_value);
//! node 23 ConstNumber pos=(1060,760)
const n23_value = 1.50;
//! node 24 Less pos=(1260,740)
const n24_out = (n6_out < n23_value);
//! node 25 And pos=(1460,600)
const n25_out = (n20_value && n22_out);
//! node 26 And pos=(1660,640)
const n26_out = (n25_out && n24_out);
//! node 27 Branch pos=(1860,80)
if (n26_out) {
//! node 28 GetGlobal pos=(1860,240) global=slain
const n28_value = ctx.getGlobal("slain");
//! node 30 AddNumber pos=(2060,240)
const n30_out = (n28_value + n29_value);
//! node 31 SetGlobal pos=(2260,80) global=slain
ctx.setGlobal("slain", n30_out);
//! node 32 ConstVec2 pos=(2260,240)
const n32_value = ctx.vec2(200.00, 230.00);
//! node 33 SetPosition2D pos=(2460,80)
ctx.setPosition2D(n32_value);
}
//! node 34 ConstNumber pos=(1660,860)
const n34_value = 0.95;
//! node 35 Less pos=(1860,860)
const n35_out = (n6_out < n34_value);
//! node 37 GetGlobal pos=(1660,960) global=hurtUntil
const n37_value = ctx.getGlobal("hurtUntil");
//! node 38 Greater pos=(1860,960)
const n38_out = (n36_value > n37_value);
//! node 39 And pos=(2060,900)
const n39_out = (n35_out && n38_out);
//! node 40 Branch pos=(2660,80)
if (n39_out) {
//! node 41 GetGlobal pos=(2660,240) global=hp
const n41_value = ctx.getGlobal("hp");
//! node 42 SubNumber pos=(2860,240)
const n42_out = (n41_value - n29_value);
//! node 43 SetGlobal pos=(3060,80) global=hp
ctx.setGlobal("hp", n42_out);
//! node 44 AddNumber pos=(2860,360)
const n44_out = (n36_value + n29_value);
//! node 45 SetGlobal pos=(3260,80) global=hurtUntil
ctx.setGlobal("hurtUntil", n44_out);
//! node 46 ConstNumber pos=(2860,480)
const n46_value = 1.20;
//! node 47 ScaleVec2 pos=(3060,440)
const n47_out = ctx.scaleVec2(n7_out, n46_value);
//! node 48 AddVec2 pos=(3260,400)
const n48_out = ctx.addVec2(n3_value, n47_out);
//! node 49 SetEntityPosition2D pos=(3460,80)
ctx.setEntityPosition2D(n2_value, n48_out);
}
}
//! endregion
```
The slime **sets its velocity**; the physics step moves it and resolves collisions. Defeat is a
move far away (spawn and destroy are coming).
## How to add the sword
A 2D Sprite `Sword` (image `mq-sword`, **Z-Order** `11`), parked at (200, 250), with this
script. While you have no sword it stays parked. Once you do, it rides at the hero's side and,
for 0.15 seconds after Space, swings out in the direction you last moved.
```tgscript
//!tgscript v1
//! script name=Sword
//! region graph
//! node 1 OnStart pos=(60,80)
export function onStart(ctx) {
//! node 2 ConstVec3 pos=(260,80)
const n2_value = ctx.vec3(0.00, -1.00, 0.00);
//! node 3 SetVarVec3 pos=(460,80) var=face
ctx.setVarVec3("face", n2_value);
}
//! node 10 OnUpdate pos=(60,320)
export function onUpdate(ctx) {
//! node 11 GetGlobal pos=(60,460) global=hasSword
const n11_value = ctx.getGlobal("hasSword");
//! node 12 ConstNumber pos=(60,560)
const n12_value = 0.50;
//! node 13 Less pos=(260,460)
const n13_out = (n11_value < n12_value);
//! node 14 Branch pos=(460,320)
if (n13_out) {
//! node 15 ConstVec2 pos=(460,480)
const n15_value = ctx.vec2(200.00, 250.00);
//! node 16 SetPosition2D pos=(660,320)
ctx.setPosition2D(n15_value);
} else {
//! node 17 ActionVector2 pos=(460,640) action=Move
const n17_value = ctx.actionVector2("Move");
//! node 18 Vec3Length pos=(660,640)
const n18_out = ctx.vec3Length(n17_value);
//! node 19 ConstNumber pos=(660,740)
const n19_value = 0.10;
//! node 20 Greater pos=(860,640)
const n20_out = (n18_out > n19_value);
//! node 21 Branch pos=(860,480)
if (n20_out) {
//! node 22 SetVarVec3 pos=(1060,480) var=face
ctx.setVarVec3("face", n17_value);
}
//! node 23 ActionPressed pos=(1060,640) action=Jump
const n23_value = ctx.actionPressed("Jump");
//! node 24 Time pos=(1060,740)
const n24_value = ctx.time();
//! node 25 Branch pos=(1260,480)
if (n23_value) {
//! node 26 SetVar pos=(1460,480) var=swingAt
ctx.setVar("swingAt", n24_value);
}
//! node 27 FindEntity pos=(1260,800) entity=Hero
const n27_value = ctx.findEntity("Hero");
//! node 28 GetEntityPosition2D pos=(1460,800)
const n28_value = ctx.getEntityPosition2D(n27_value);
//! node 29 GetVarVec3 pos=(1260,900) var=face
const n29_value = ctx.getVarVec3("face");
//! node 30 Vec3X pos=(1460,900)
const n30_out = ctx.vec3X(n29_value);
//! node 31 Vec3Y pos=(1460,1000)
const n31_out = ctx.vec3Y(n29_value);
//! node 32 MakeVec2 pos=(1660,940)
const n32_out = ctx.makeVec2(n30_out, n31_out);
//! node 33 Vec2Normalize pos=(1860,940)
const n33_out = ctx.vec2Normalize(n32_out);
//! node 34 GetVar pos=(1460,1100) var=swingAt
const n34_value = ctx.getVar("swingAt");
//! node 35 SubNumber pos=(1660,1100)
const n35_out = (n24_value - n34_value);
//! node 36 ConstNumber pos=(1660,1200)
const n36_value = 0.15;
//! node 37 Less pos=(1860,1100)
const n37_out = (n35_out < n36_value);
//! node 38 Branch pos=(2060,480)
if (n37_out) {
//! node 39 ConstNumber pos=(2060,640)
const n39_value = 0.80;
//! node 40 ScaleVec2 pos=(2260,640)
const n40_out = ctx.scaleVec2(n33_out, n39_value);
//! node 41 AddVec2 pos=(2460,640)
const n41_out = ctx.addVec2(n28_value, n40_out);
//! node 42 SetPosition2D pos=(2660,480)
ctx.setPosition2D(n41_out);
//! node 43 Vec2ToAngle pos=(2260,760)
const n43_out = ctx.vec2ToAngle(n33_out);
//! node 44 ConstNumber pos=(2260,860)
const n44_value = -45.00;
//! node 45 AddNumber pos=(2460,800)
const n45_out = (n43_out + n44_value);
//! node 46 SetAngle2D pos=(2860,480)
ctx.setAngle2D(n45_out);
} else {
//! node 47 ConstVec2 pos=(2260,960)
const n47_value = ctx.vec2(0.45, -0.15);
//! node 48 AddVec2 pos=(2460,960)
const n48_out = ctx.addVec2(n28_value, n47_value);
//! node 49 SetPosition2D pos=(2660,640)
ctx.setPosition2D(n48_out);
//! node 50 ConstNumber pos=(2460,1060)
const n50_value = 0.00;
//! node 51 SetAngle2D pos=(2860,640)
ctx.setAngle2D(n50_value);
}
}
}
//! endregion
```
It remembers the last direction in a **per-entity variable** (`face`, set to "down" in
**OnStart**) and the swing time in another (`swingAt`), compared against **Time**.
## How to add hearts and respawning
1. Three 2D Sprites `Heart1`, `Heart2`, `Heart3`, image `mq-heart`, **Scale** `0.5`, `0.5`
(the image is 8×8 pixels, so this keeps 16 px per unit), **Z-Order** `71`.
2. A 2D Sprite `Hud` with its **Tint A** set to `0` (it only carries the script), and script
`Health`. **OnStart** sets `hp` to 3. Every frame it places each heart on the camera if
`hp` is high enough, respawns the hero when `hp` reaches 0, and drinks a potion on
Q ([Part 11](/rpg2d/11-inventory/)).
```tgscript
//!tgscript v1
//! script name=Health
//! region graph
//! node 1 OnStart pos=(60,80)
export function onStart(ctx) {
//! node 2 ConstNumber pos=(260,80)
const n2_value = 3.00;
//! node 3 SetGlobal pos=(460,80) global=hp
ctx.setGlobal("hp", n2_value);
}
//! node 10 OnUpdate pos=(60,320)
export function onUpdate(ctx) {
//! node 11 FindEntity pos=(60,460) entity=Camera
const n11_value = ctx.findEntity("Camera");
//! node 12 GetEntityPosition2D pos=(260,460)
const n12_value = ctx.getEntityPosition2D(n11_value);
//! node 13 GetGlobal pos=(60,560) global=hp
const n13_value = ctx.getGlobal("hp");
//! node 14 GetGlobal pos=(60,660) global=started
const n14_value = ctx.getGlobal("started");
//! node 15 ConstNumber pos=(60,760)
const n15_value = 0.50;
//! node 16 Greater pos=(260,660)
const n16_out = (n14_value > n15_value);
//! node 17 ConstVec2 pos=(260,760)
const n17_value = ctx.vec2(200.00, 260.00);
//! node 31 FindEntity pos=(260,900) entity=Heart1
const n31_value = ctx.findEntity("Heart1");
//! node 32 ConstVec2 pos=(260,1000)
const n32_value = ctx.vec2(-0.70, 3.70);
//! node 33 AddVec2 pos=(460,1000)
const n33_out = ctx.addVec2(n12_value, n32_value);
//! node 34 ConstNumber pos=(260,1100)
const n34_value = 0.50;
//! node 35 Greater pos=(460,1100)
const n35_out = (n13_value > n34_value);
//! node 36 And pos=(660,1100)
const n36_out = (n35_out && n16_out);
//! node 37 Branch pos=(1060,320)
if (n36_out) {
//! node 38 SetEntityPosition2D pos=(1260,320)
ctx.setEntityPosition2D(n31_value, n33_out);
} else {
//! node 39 SetEntityPosition2D pos=(1260,480)
ctx.setEntityPosition2D(n31_value, n17_value);
}
//! node 40 FindEntity pos=(260,1320) entity=Heart2
const n40_value = ctx.findEntity("Heart2");
//! node 41 ConstVec2 pos=(260,1420)
const n41_value = ctx.vec2(0.00, 3.70);
//! node 42 AddVec2 pos=(460,1420)
const n42_out = ctx.addVec2(n12_value, n41_value);
//! node 43 ConstNumber pos=(260,1520)
const n43_value = 1.50;
//! node 44 Greater pos=(460,1520)
const n44_out = (n13_value > n43_value);
//! node 45 And pos=(660,1520)
const n45_out = (n44_out && n16_out);
//! node 46 Branch pos=(1560,320)
if (n45_out) {
//! node 47 SetEntityPosition2D pos=(1760,320)
ctx.setEntityPosition2D(n40_value, n42_out);
} else {
//! node 48 SetEntityPosition2D pos=(1760,480)
ctx.setEntityPosition2D(n40_value, n17_value);
}
//! node 49 FindEntity pos=(260,1740) entity=Heart3
const n49_value = ctx.findEntity("Heart3");
//! node 50 ConstVec2 pos=(260,1840)
const n50_value = ctx.vec2(0.70, 3.70);
//! node 51 AddVec2 pos=(460,1840)
const n51_out = ctx.addVec2(n12_value, n50_value);
//! node 52 ConstNumber pos=(260,1940)
const n52_value = 2.50;
//! node 53 Greater pos=(460,1940)
const n53_out = (n13_value > n52_value);
//! node 54 And pos=(660,1940)
const n54_out = (n53_out && n16_out);
//! node 55 Branch pos=(2060,320)
if (n54_out) {
//! node 56 SetEntityPosition2D pos=(2260,320)
ctx.setEntityPosition2D(n49_value, n51_out);
} else {
//! node 57 SetEntityPosition2D pos=(2260,480)
ctx.setEntityPosition2D(n49_value, n17_value);
}
//! node 58 Less pos=(260,2300)
const n58_out = (n13_value < n15_value);
//! node 59 And pos=(460,2300)
const n59_out = (n58_out && n16_out);
//! node 60 Branch pos=(2600,320)
if (n59_out) {
//! node 61 FindEntity pos=(2600,480) entity=Hero
const n61_value = ctx.findEntity("Hero");
//! node 62 ConstVec2 pos=(2600,580)
const n62_value = ctx.vec2(0.00, -8.00);
//! node 63 SetEntityPosition2D pos=(2800,320)
ctx.setEntityPosition2D(n61_value, n62_value);
//! node 64 ConstNumber pos=(2800,480)
const n64_value = 3.00;
//! node 65 SetGlobal pos=(3000,320) global=hp
ctx.setGlobal("hp", n64_value);
}
//! node 66 KeyDown pos=(260,2500) key=Q
const n66_value = ctx.keyDown("Q");
//! node 67 GetGlobal pos=(260,2600) global=potions
const n67_value = ctx.getGlobal("potions");
//! node 68 Greater pos=(460,2600)
const n68_out = (n67_value > n15_value);
//! node 69 ConstNumber pos=(260,2700)
const n69_value = 2.50;
//! node 70 Less pos=(460,2700)
const n70_out = (n13_value < n69_value);
//! node 71 And pos=(660,2550)
const n71_out = (n66_value && n68_out);
//! node 72 And pos=(860,2600)
const n72_out = (n71_out && n70_out);
//! node 73 Branch pos=(3200,320)
if (n72_out) {
//! node 74 ConstNumber pos=(3200,480)
const n74_value = 3.00;
//! node 75 SetGlobal pos=(3400,320) global=hp
ctx.setGlobal("hp", n74_value);
//! node 76 ConstNumber pos=(3200,580)
const n76_value = 1.00;
//! node 77 SubNumber pos=(3400,580)
const n77_out = (n67_value - n76_value);
//! node 78 SetGlobal pos=(3600,320) global=potions
ctx.setGlobal("potions", n77_out);
}
}
//! endregion
```
## Good practices
- **Let physics move fighters.** Slimes set velocity and have bodies, so they never pass through
walls or each other. A script that teleports enemies around fights the physics engine.
- **Give hits a cooldown.** Without `hurtUntil`, a slime touching the hero would take a heart
every frame (50 per second).
- **One source of truth for health.** Only scripts write `hp`; the hearts just display it. To
add armour or a bigger health bar, change the numbers, not the drawing code.
- **Reset in OnStart.** Globals reset when you press **Stop**; **OnStart** puts back the
starting values when you press **Play**.
- **Split big scripts by job.** Health and inventory are separate scripts on separate entities,
so each graph stays readable.
## This part's assets
[Slime.tgscript](/downloads/meadow-quest/Slime.tgscript) ·
[Sword.tgscript](/downloads/meadow-quest/Sword.tgscript) ·
[Health.tgscript](/downloads/meadow-quest/Health.tgscript) ·
[mq-slime.png](/downloads/meadow-quest/mq-slime.png) ·
[mq-sword.png](/downloads/meadow-quest/mq-sword.png) ·
[mq-heart.png](/downloads/meadow-quest/mq-heart.png) (each image with its `.mt`).
[Next: inventory →](/rpg2d/11-inventory/)
---
# 11. Inventory & potions
URL: https://wiki.trisgine.com/rpg2d/11-inventory/
A five-slot item bar on screen that shows what the hero carries, and a potion to pick up and drink.

## How it works
The inventory is the game state you already have, shown on screen. Each slot's icon is a
sprite that the `Inventory` script places on the bar when the matching global says you own
it, and parks otherwise:
| Slot | Shows when |
|---|---|
| 1: sword | `hasSword` = 1 |
| 2–4: coins | `coins` ≥ 1, 2, 3 |
| 5: potion | `potions` ≥ 1 |
## How to build the bar
1. A 2D Sprite `Inventory`, image `mq-invbar`, **Scale** `5`, `1` (80×16 pixels: five tiles),
**Z-Order** `70`, parked at (200, 280).
2. Icon sprites, **Z-Order** `71`, parked at (200, 280): `SwordIcon` (image `mq-sword`),
`CoinIcon1`, `CoinIcon2`, `CoinIcon3` (image `mq-coin`), and `PotionIcon` (image
`mq-potion`).
3. Script `Inventory` on the `Inventory` sprite:
```tgscript
//!tgscript v1
//! script name=Inventory
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,240) entity=Camera
const n2_value = ctx.findEntity("Camera");
//! node 3 GetEntityPosition2D pos=(260,240)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 GetGlobal pos=(60,340) global=started
const n4_value = ctx.getGlobal("started");
//! node 5 ConstNumber pos=(60,440)
const n5_value = 0.50;
//! node 6 Greater pos=(260,340)
const n6_out = (n4_value > n5_value);
//! node 7 ConstVec2 pos=(260,440)
const n7_value = ctx.vec2(200.00, 280.00);
//! node 8 ConstVec2 pos=(260,540)
const n8_value = ctx.vec2(0.00, -3.55);
//! node 9 AddVec2 pos=(460,500)
const n9_out = ctx.addVec2(n3_value, n8_value);
//! node 10 Branch pos=(660,80)
if (n6_out) {
//! node 11 SetPosition2D pos=(860,80)
ctx.setPosition2D(n9_out);
} else {
//! node 12 SetPosition2D pos=(860,240)
ctx.setPosition2D(n7_value);
}
//! node 21 FindEntity pos=(60,700) entity=SwordIcon
const n21_value = ctx.findEntity("SwordIcon");
//! node 22 GetGlobal pos=(60,800) global=hasSword
const n22_value = ctx.getGlobal("hasSword");
//! node 23 ConstNumber pos=(60,900)
const n23_value = 0.50;
//! node 24 Greater pos=(260,800)
const n24_out = (n22_value > n23_value);
//! node 25 And pos=(460,800)
const n25_out = (n24_out && n6_out);
//! node 26 ConstVec2 pos=(260,1000)
const n26_value = ctx.vec2(-2.00, -3.55);
//! node 27 AddVec2 pos=(460,1000)
const n27_out = ctx.addVec2(n3_value, n26_value);
//! node 28 Branch pos=(1060,80)
if (n25_out) {
//! node 29 SetEntityPosition2D pos=(1260,80)
ctx.setEntityPosition2D(n21_value, n27_out);
} else {
//! node 30 SetEntityPosition2D pos=(1260,240)
ctx.setEntityPosition2D(n21_value, n7_value);
}
//! node 31 FindEntity pos=(60,1120) entity=CoinIcon1
const n31_value = ctx.findEntity("CoinIcon1");
//! node 32 GetGlobal pos=(60,1220) global=coins
const n32_value = ctx.getGlobal("coins");
//! node 33 ConstNumber pos=(60,1320)
const n33_value = 0.50;
//! node 34 Greater pos=(260,1220)
const n34_out = (n32_value > n33_value);
//! node 35 And pos=(460,1220)
const n35_out = (n34_out && n6_out);
//! node 36 ConstVec2 pos=(260,1420)
const n36_value = ctx.vec2(-1.00, -3.55);
//! node 37 AddVec2 pos=(460,1420)
const n37_out = ctx.addVec2(n3_value, n36_value);
//! node 38 Branch pos=(1560,80)
if (n35_out) {
//! node 39 SetEntityPosition2D pos=(1760,80)
ctx.setEntityPosition2D(n31_value, n37_out);
} else {
//! node 40 SetEntityPosition2D pos=(1760,240)
ctx.setEntityPosition2D(n31_value, n7_value);
}
//! node 41 FindEntity pos=(60,1540) entity=CoinIcon2
const n41_value = ctx.findEntity("CoinIcon2");
//! node 42 GetGlobal pos=(60,1640) global=coins
const n42_value = ctx.getGlobal("coins");
//! node 43 ConstNumber pos=(60,1740)
const n43_value = 1.50;
//! node 44 Greater pos=(260,1640)
const n44_out = (n42_value > n43_value);
//! node 45 And pos=(460,1640)
const n45_out = (n44_out && n6_out);
//! node 46 ConstVec2 pos=(260,1840)
const n46_value = ctx.vec2(0.00, -3.55);
//! node 47 AddVec2 pos=(460,1840)
const n47_out = ctx.addVec2(n3_value, n46_value);
//! node 48 Branch pos=(2060,80)
if (n45_out) {
//! node 49 SetEntityPosition2D pos=(2260,80)
ctx.setEntityPosition2D(n41_value, n47_out);
} else {
//! node 50 SetEntityPosition2D pos=(2260,240)
ctx.setEntityPosition2D(n41_value, n7_value);
}
//! node 51 FindEntity pos=(60,1960) entity=CoinIcon3
const n51_value = ctx.findEntity("CoinIcon3");
//! node 52 GetGlobal pos=(60,2060) global=coins
const n52_value = ctx.getGlobal("coins");
//! node 53 ConstNumber pos=(60,2160)
const n53_value = 2.50;
//! node 54 Greater pos=(260,2060)
const n54_out = (n52_value > n53_value);
//! node 55 And pos=(460,2060)
const n55_out = (n54_out && n6_out);
//! node 56 ConstVec2 pos=(260,2260)
const n56_value = ctx.vec2(1.00, -3.55);
//! node 57 AddVec2 pos=(460,2260)
const n57_out = ctx.addVec2(n3_value, n56_value);
//! node 58 Branch pos=(2560,80)
if (n55_out) {
//! node 59 SetEntityPosition2D pos=(2760,80)
ctx.setEntityPosition2D(n51_value, n57_out);
} else {
//! node 60 SetEntityPosition2D pos=(2760,240)
ctx.setEntityPosition2D(n51_value, n7_value);
}
//! node 61 FindEntity pos=(60,2380) entity=PotionIcon
const n61_value = ctx.findEntity("PotionIcon");
//! node 62 GetGlobal pos=(60,2480) global=potions
const n62_value = ctx.getGlobal("potions");
//! node 63 ConstNumber pos=(60,2580)
const n63_value = 0.50;
//! node 64 Greater pos=(260,2480)
const n64_out = (n62_value > n63_value);
//! node 65 And pos=(460,2480)
const n65_out = (n64_out && n6_out);
//! node 66 ConstVec2 pos=(260,2680)
const n66_value = ctx.vec2(2.00, -3.55);
//! node 67 AddVec2 pos=(460,2680)
const n67_out = ctx.addVec2(n3_value, n66_value);
//! node 68 Branch pos=(3060,80)
if (n65_out) {
//! node 69 SetEntityPosition2D pos=(3260,80)
ctx.setEntityPosition2D(n61_value, n67_out);
} else {
//! node 70 SetEntityPosition2D pos=(3260,240)
ctx.setEntityPosition2D(n61_value, n7_value);
}
}
//! endregion
```
## How to add a potion
1. A 2D Sprite `Potion` (image `mq-potion`, **Z-Order** `8`) at (7, -1).
2. Script `Potion`: a pickup like the coin, counting into `potions`. (Part 12 turns it into a
trigger with a sound, like the coins.)
```tgscript
//!tgscript v1
//! script name=Potion
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,220) entity=Hero
const n2_value = ctx.findEntity("Hero");
//! node 3 GetEntityPosition2D pos=(260,220)
const n3_value = ctx.getEntityPosition2D(n2_value);
//! node 4 GetPosition2D pos=(260,340)
const n4_value = ctx.getPosition2D();
//! node 5 Vec2Distance pos=(460,260)
const n5_out = ctx.vec2Distance(n3_value, n4_value);
//! node 6 ConstNumber pos=(460,380)
const n6_value = 0.80;
//! node 7 Less pos=(660,260)
const n7_out = (n5_out < n6_value);
//! node 8 Branch pos=(860,80)
if (n7_out) {
//! node 9 GetGlobal pos=(860,240) global=potions
const n9_value = ctx.getGlobal("potions");
//! node 10 ConstNumber pos=(860,340)
const n10_value = 1.00;
//! node 11 AddNumber pos=(1060,280)
const n11_out = (n9_value + n10_value);
//! node 12 SetGlobal pos=(1260,80) global=potions
ctx.setGlobal("potions", n11_out);
//! node 13 ConstVec2 pos=(1260,240)
const n13_value = ctx.vec2(200.00, 270.00);
//! node 14 SetPosition2D pos=(1460,80)
ctx.setPosition2D(n13_value);
}
}
//! endregion
```
Drinking is already in the `Health` script from [Part 10](/rpg2d/10-combat-and-health/): when
you hold Q, have a potion and fewer than three hearts, `hp` goes back to 3 and
`potions` goes down by one.
## Good practices
- **The inventory is data, the bar is a view.** Items are numbers in globals; the bar only
displays them. Saving, trading or a shop later only need to change the numbers.
- **HUD follows the camera.** Every slot is placed at "camera + offset", so it stays put on the
screen however the camera moves.
- **Keep the HUD inside the view.** With a 9-unit-tall camera the edges are at ±4.5; the bar at
-3.55 and the hearts at 3.7 stay clear of them.
- **Show the HUD only while playing.** Every slot is parked until `started` is set, so the title
screen stays clean.
- **Grow it with the game.** Five slots fit three kinds of item; add a slot when you add an
item, and a global to count it.
## This part's assets
[Inventory.tgscript](/downloads/meadow-quest/Inventory.tgscript) ·
[Potion.tgscript](/downloads/meadow-quest/Potion.tgscript) ·
[mq-invbar.png](/downloads/meadow-quest/mq-invbar.png) ·
[mq-potion.png](/downloads/meadow-quest/mq-potion.png) (each image with its `.mt`).
[Next: sound effects & triggers →](/rpg2d/12-sounds-and-triggers/)
---
# 12. Sound effects & trigger pickups
URL: https://wiki.trisgine.com/rpg2d/12-sounds-and-triggers/
Turn the coins and the potion into triggers that react the moment the hero touches them, and play a sound for every pickup, swing, hit and gate.
Two upgrades in one part. The coins and the potion stop measuring distances every frame and become
**triggers**, and the game gets **sound effects**: a chime for pickups, a whoosh for the sword, a
thud when a slime hits you, a pop when one is defeated, a fanfare for the gate and a gulp for the
potion.
## Triggers instead of distance checks
A **trigger** (a *sensor* collider) blocks nothing. Instead, the physics step tells the scripts on
both sides when a body enters or leaves it, through the **OnTriggerEnter** and **OnTriggerExit**
events. The hero already has a **Physics Body 2D** (Part 3), so a coin only needs a collider marked
as a sensor; it stays static.
1. Select **Coin1**. **Add Component > Collider 2D**.
2. In **Physics 2D > Collider 2D**: **Shape** `Circle`, **Radius** `0.35`, and tick
**Is sensor (trigger)**.
3. Do the same for **Coin2**, **Coin3** and the **Potion**.

Now rewrite `MeadowCoin`. **OnTriggerEnter** replaces **OnUpdate**, and **ContactOther** (the entity
that touched the coin) replaces the distance check:
```text
OnTriggerEnter ─▶ Branch( ContactOther == FindEntity Hero )
then ─▶ SetGlobal coins = GetGlobal coins + 1
─▶ PlayAudio( FindEntity SfxCoin )
─▶ SetPosition2D( 200 , 200 )
```

```tgscript
//!tgscript v1
//! script name=MeadowCoin
//! region graph
//! node 1 OnTriggerEnter pos=(60,80)
export function onTriggerEnter(ctx) {
//! node 2 ContactOther pos=(60,220)
const n2_value = ctx.contactOther();
//! node 3 FindEntity pos=(60,320) entity=Hero
const n3_value = ctx.findEntity("Hero");
//! node 4 Equal pos=(260,260)
const n4_out = (n2_value === n3_value);
//! node 5 Branch pos=(460,80)
if (n4_out) {
//! node 6 GetGlobal pos=(460,240) global=coins
const n6_value = ctx.getGlobal("coins");
//! node 7 ConstNumber pos=(460,340)
const n7_value = 1.00;
//! node 8 AddNumber pos=(660,280)
const n8_out = (n6_value + n7_value);
//! node 9 SetGlobal pos=(660,80) global=coins
ctx.setGlobal("coins", n8_out);
//! node 10 FindEntity pos=(660,420) entity=SfxCoin
const n10_value = ctx.findEntity("SfxCoin");
//! node 11 PlayAudio pos=(860,80)
ctx.playAudio(n10_value);
//! node 12 ConstVec2 pos=(860,240)
const n12_value = ctx.vec2(200.00, 200.00);
//! node 13 SetPosition2D pos=(1060,80)
ctx.setPosition2D(n12_value);
}
}
//! endregion
```
The potion's script is the same graph with `potions` instead of `coins` and its own parking spot:
```tgscript
//!tgscript v1
//! script name=Potion
//! region graph
//! node 1 OnTriggerEnter pos=(60,80)
export function onTriggerEnter(ctx) {
//! node 2 ContactOther pos=(60,220)
const n2_value = ctx.contactOther();
//! node 3 FindEntity pos=(60,320) entity=Hero
const n3_value = ctx.findEntity("Hero");
//! node 4 Equal pos=(260,260)
const n4_out = (n2_value === n3_value);
//! node 5 Branch pos=(460,80)
if (n4_out) {
//! node 6 GetGlobal pos=(460,240) global=potions
const n6_value = ctx.getGlobal("potions");
//! node 7 ConstNumber pos=(460,340)
const n7_value = 1.00;
//! node 8 AddNumber pos=(660,280)
const n8_out = (n6_value + n7_value);
//! node 9 SetGlobal pos=(660,80) global=potions
ctx.setGlobal("potions", n8_out);
//! node 10 FindEntity pos=(660,420) entity=SfxCoin
const n10_value = ctx.findEntity("SfxCoin");
//! node 11 PlayAudio pos=(860,80)
ctx.playAudio(n10_value);
//! node 12 ConstVec2 pos=(860,240)
const n12_value = ctx.vec2(200.00, 270.00);
//! node 13 SetPosition2D pos=(1060,80)
ctx.setPosition2D(n12_value);
}
}
//! endregion
```
## Sound effects
Each sound is its own **Audio Source** entity, started by a script with **PlayAudio**.
| Entity | Clip | Played by |
|---|---|---|
| `SfxCoin` | `mq-sfx-coin.wav` | MeadowCoin, Potion (pickup) |
| `SfxSwing` | `mq-sfx-swing.wav` | Sword (swing) |
| `SfxHurt` | `mq-sfx-hurt.wav` | Slime (a hit), GameOver |
| `SfxDefeat` | `mq-sfx-defeat.wav` | Slime (defeated) |
| `SfxGate` | `mq-sfx-gate.wav` | Gate (opens) |
| `SfxDrink` | `mq-sfx-drink.wav` | Health (potion drunk) |
### How to make one
1. **Project > Import…** the `.wav` files from [this part's assets](#this-parts-assets) into
`Assets/Audio` (with their `.mt` files).
2. Right-click the Hierarchy, then **Audio Source**. Rename it `SfxCoin`.
3. In **Audio Source**, click **Choose clip…** and pick `mq-sfx-coin.wav`.
4. Set **Gain** `0.8`, **Att Min** `100` and **Att Max** `200`, like the music: the sound is
equally loud wherever the camera is.
5. Untick **Loop** and **Autoplay**: it plays only when a script asks.
6. **Add Component > Script** and give it this tiny script, `Sfx`:
```tgscript
//!tgscript v1
//! script name=Sfx
//! region graph
//! node 1 OnStart pos=(60,80)
export function onStart(ctx) {
//! node 2 StopAudio pos=(260,80)
ctx.stopAudio(/*!unconnected*/ 0);
}
//! endregion
```

> [!NOTE]
> Why the `Sfx` script? **Save Scene** keeps an Audio Source's Gain, Att Min, Att Max and Loop,
> but not **Autoplay** yet, so after reopening the scene every sound would play once when you press
> **Play**. **StopAudio** in **OnStart** silences it. One script serves all six sounds.
7. Select `SfxCoin`, press Ctrl+D five times, and give each copy its name and
clip from the table.
### Playing them
**PlayAudio** plays the Audio Source of the entity wired into it. Add two nodes where the event
happens: **FindEntity** (the sound's name) → **PlayAudio**.
| Script | Where | Sound |
|---|---|---|
| `Sword` | after **SetVar** `swingAt`, in the Branch that starts a swing | `SfxSwing` |
| `Slime` | after **SetPosition2D** in the *defeated* Branch | `SfxDefeat` |
| `Slime` | after **SetEntityPosition2D** in the *hit* Branch (the knockback) | `SfxHurt` |
| `Health` | after the last **SetGlobal** `potions` (drinking) | `SfxDrink` |
The gate needs one more idea. Its old graph moved it away on *every* frame once you had three coins;
a sound there would restart every frame. A per-entity variable, `open`, makes it happen once:
```text
OnUpdate ─▶ Branch( coins >= 3 And GetVar open < 0.5 )
then ─▶ SetVar open = 1 ─▶ PlayAudio( SfxGate ) ─▶ SetPosition2D( 200 , 210 )
```
```tgscript
//!tgscript v1
//! script name=Gate
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetGlobal pos=(60,220) global=coins
const n2_value = ctx.getGlobal("coins");
//! node 3 ConstNumber pos=(60,320)
const n3_value = 3.00;
//! node 4 GreaterEqual pos=(260,260)
const n4_out = (n2_value >= n3_value);
//! node 5 GetVar pos=(60,420) var=open
const n5_value = ctx.getVar("open");
//! node 6 ConstNumber pos=(60,520)
const n6_value = 0.50;
//! node 7 Less pos=(260,460)
const n7_out = (n5_value < n6_value);
//! node 8 And pos=(460,360)
const n8_out = (n4_out && n7_out);
//! node 9 Branch pos=(660,80)
if (n8_out) {
//! node 10 ConstNumber pos=(660,240)
const n10_value = 1.00;
//! node 11 SetVar pos=(860,80) var=open
ctx.setVar("open", n10_value);
//! node 12 FindEntity pos=(860,240) entity=SfxGate
const n12_value = ctx.findEntity("SfxGate");
//! node 13 PlayAudio pos=(1060,80)
ctx.playAudio(n12_value);
//! node 14 ConstVec2 pos=(1060,240)
const n14_value = ctx.vec2(200.00, 210.00);
//! node 15 SetPosition2D pos=(1260,80)
ctx.setPosition2D(n14_value);
}
}
//! endregion
```
**Play** and collect a coin: you hear it.
## Good practices
- **Triggers for pickups, distances for "near".** A pickup happens on contact, so a trigger is
exact and costs nothing between contacts. "Is the hero close enough to talk?" (the farmer) is a
range, not a contact, so a distance check is still right there.
- **Check who touched you.** Slimes and the dog can touch a coin too; comparing **ContactOther**
with the hero keeps them from collecting it.
- **Play a sound on an event, never every frame.** A trigger, a key press or a state change (the
gate's `open`) fires once. A sound started every frame restarts every frame.
- **One entity per sound, named by purpose.** `SfxHurt` says what it is for; scripts find it by
that name, so you can swap the clip without touching a graph.
- **Keep effects short and below the music.** These are 0.1 to 0.5 seconds long at gain 0.8 against
music at 0.5. Generate or record them at the same sample rate as the music.
## This part's assets
[MeadowCoin.tgscript](/downloads/meadow-quest/MeadowCoin.tgscript) ·
[Potion.tgscript](/downloads/meadow-quest/Potion.tgscript) ·
[Gate.tgscript](/downloads/meadow-quest/Gate.tgscript) ·
[Sfx.tgscript](/downloads/meadow-quest/Sfx.tgscript) ·
[Sword.tgscript](/downloads/meadow-quest/Sword.tgscript) ·
[Slime.tgscript](/downloads/meadow-quest/Slime.tgscript) ·
[Health.tgscript](/downloads/meadow-quest/Health.tgscript)
Sounds (each with its `.mt`):
[mq-sfx-coin.wav](/downloads/meadow-quest/mq-sfx-coin.wav) ·
[mq-sfx-swing.wav](/downloads/meadow-quest/mq-sfx-swing.wav) ·
[mq-sfx-hurt.wav](/downloads/meadow-quest/mq-sfx-hurt.wav) ·
[mq-sfx-defeat.wav](/downloads/meadow-quest/mq-sfx-defeat.wav) ·
[mq-sfx-gate.wav](/downloads/meadow-quest/mq-sfx-gate.wav) ·
[mq-sfx-drink.wav](/downloads/meadow-quest/mq-sfx-drink.wav)
[Next: a quest line on screen →](/rpg2d/13-quest-text/)
---
# 13. A quest line on screen
URL: https://wiki.trisgine.com/rpg2d/13-quest-text/
A UI canvas with one line of text that a script keeps up to date with SetText and SetTextNumber, telling the player what to do next.

The game now tells the player what to do next, in one line at the top of the screen:
| When | The line says |
|---|---|
| on the title screen | Meadow Quest |
| no sword yet | Talk to the farmer |
| fewer than 2 slimes defeated | Slimes left: 2, then 1 |
| fewer than 3 coins | Coins to find: 3, 2, 1 |
| the gate is open | Open the chest! |
| you won | You did it! |
The line is **UI text**, not a sprite: a script can change it while the game runs, and it uses a
real font, so it is sharp at any size.
## How to make the canvas
1. Right-click the Hierarchy, then **UI > Canvas (Screen)**. Rename it `MeadowHud`.
2. With `MeadowHud` selected, right-click the Hierarchy, then **UI > Panel**. Rename it
`HudPage`, pick the **stretch** anchor preset (the bottom-right one) and set its tint's **A** to
`0`. It is an invisible frame for everything shown during play; the menu in
[Part 15](/rpg2d/15-main-menu/) hides and shows it by this name.
3. With `HudPage` selected, **UI > Panel** again. Rename it `QuestPanel`. In its **UI Element**
section, click the **top-centre** anchor preset, then set
**Pos Y** `100`, **Width** `640` and **Height** `60` (the canvas is 1920×1080 units, scaled to
the view). Give it a dark, slightly see-through tint so the text reads on grass.
4. With `QuestPanel` selected, **UI > Text**. Rename it `QuestText`. Pick the **stretch** anchor
preset (the bottom-right one) so it fills the panel, and in **Text Style** set the size to `30`,
centre it, and type `Meadow Quest` in the text box (press Enter to apply).

**Save Scene** also writes the canvas to its own `.uidoc` file.
## How to write the script
A 2D Sprite `QuestBook` with its **Tint A** at `0` (it only carries the script), and the script
`Quest`. It reads the globals the other scripts already keep, and picks the line:
```text
OnUpdate ─▶ Branch( started < 0.5 ) then: SetText "Meadow Quest"
else Branch( hasSword < 0.5 ) then: SetText "Talk to the farmer"
else Branch( slain < 2 ) then: SetTextNumber "Slimes left: " , 2 - slain
else Branch( coins < 3 ) then: SetTextNumber "Coins to find: " , 3 - coins
else Branch( won < 0.5 ) then: SetText "Open the chest!"
else SetText "You did it!"
```
**SetText** writes its `text` attribute into the UI Text element wired to its `element` input;
**FindEntity** `QuestText` finds it by name. **SetTextNumber** writes its `prefix` followed by a
number: `Slimes left: ` and `2 − slain` show *Slimes left: 1*. Whole numbers print without decimals.

```tgscript
//!tgscript v1
//! script name=Quest
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,220) entity=QuestText
const n2_value = ctx.findEntity("QuestText");
//! node 3 GetGlobal pos=(60,320) global=hasSword
const n3_value = ctx.getGlobal("hasSword");
//! node 4 GetGlobal pos=(60,420) global=slain
const n4_value = ctx.getGlobal("slain");
//! node 5 GetGlobal pos=(60,520) global=coins
const n5_value = ctx.getGlobal("coins");
//! node 6 GetGlobal pos=(60,620) global=won
const n6_value = ctx.getGlobal("won");
//! node 7 ConstNumber pos=(60,720)
const n7_value = 0.50;
//! node 8 ConstNumber pos=(60,820)
const n8_value = 2.00;
//! node 9 ConstNumber pos=(60,920)
const n9_value = 3.00;
//! node 10 Less pos=(260,320)
const n10_out = (n3_value < n7_value);
//! node 11 Less pos=(260,420)
const n11_out = (n4_value < n8_value);
//! node 12 Less pos=(260,520)
const n12_out = (n5_value < n9_value);
//! node 13 Less pos=(260,620)
const n13_out = (n6_value < n7_value);
//! node 30 GetGlobal pos=(60,1020) global=started
const n30_value = ctx.getGlobal("started");
//! node 31 Less pos=(260,1020)
const n31_out = (n30_value < n7_value);
//! node 32 Branch pos=(460,1020)
if (n31_out) {
//! node 33 SetText pos=(660,1020) text="Meadow Quest"
ctx.setText("Meadow Quest", n2_value);
} else {
//! node 14 Branch pos=(460,80)
if (n10_out) {
//! node 15 SetText pos=(660,80) text="Talk to the farmer"
ctx.setText("Talk to the farmer", n2_value);
} else {
//! node 16 Branch pos=(660,240)
if (n11_out) {
//! node 17 SubNumber pos=(660,420)
const n17_out = (n8_value - n4_value);
//! node 18 SetTextNumber pos=(860,240) prefix="Slimes left: "
ctx.setTextNumber("Slimes left: ", n2_value, n17_out);
} else {
//! node 19 Branch pos=(860,400)
if (n12_out) {
//! node 20 SubNumber pos=(860,560)
const n20_out = (n9_value - n5_value);
//! node 21 SetTextNumber pos=(1060,400) prefix="Coins to find: "
ctx.setTextNumber("Coins to find: ", n2_value, n20_out);
} else {
//! node 22 Branch pos=(1060,560)
if (n13_out) {
//! node 23 SetText pos=(1260,560) text="Open the chest!"
ctx.setText("Open the chest!", n2_value);
} else {
//! node 24 SetText pos=(1260,720) text="You did it!"
ctx.setText("You did it!", n2_value);
}
}
}
}
}
}
//! endregion
```
> [!TIP]
> Big graphs get messy fast. **Arrange** in the Script Editor's toolbar lays the nodes out left to
> right by their wires; **Frame** then fits them all in view.
## Good practices
- **The text follows the state.** The quest line keeps no memory of its own: every frame it looks
at `hasSword`, `slain`, `coins` and `won` and shows the matching line, so it can never fall out of
step with the game.
- **One script writes a text element.** If two scripts set `QuestText`, the last one each frame
wins and the line flickers between them.
- **UI text for words that change, pixel art for words that don't.** The GAME OVER plaque and the
speech bubbles are painted sprites that match the art; the quest line changes, so it is UI text.
- **Keep HUD text short and in one place.** One line under the hearts is easy to glance at;
sentences belong in dialogue.
- **Give text a backing.** White text on grass and sand is hard to read; a dark panel behind it fixes
that on every background.
## This part's assets
[Quest.tgscript](/downloads/meadow-quest/Quest.tgscript) ·
[MeadowHud.uidoc](/downloads/meadow-quest/MeadowHud.uidoc)
The downloadable `MeadowHud.uidoc` is the finished canvas: it also has the menu page from
[Part 15](/rpg2d/15-main-menu/) and an empty `QuestCount` text from [Part 16](/rpg2d/16-languages/).
[Next: game over →](/rpg2d/14-game-over/)
---
# 14. Game over & restart
URL: https://wiki.trisgine.com/rpg2d/14-game-over/
Replace respawning with a GAME OVER plaque, freeze the game for a moment, and restart the whole scene with LoadScene.

So far, losing your last heart just put the hero back at the start. Now losing means something:
everything stops, a **GAME OVER** plaque appears, and after two and a half seconds the whole scene
starts again from the title screen, with three hearts, no sword and every coin back in place.
## How to build it
1. **Remove the respawn from `Health`.** Open it in the Script Editor, select the Branch that moves
the hero to (0, −8) and sets `hp` to 3, together with its **Less** and **And** condition nodes and
the five nodes in its *then* branch, and press Delete. Hearts and potions stay as they are.
2. **The plaque:** a 2D Sprite `GameOverBanner`, image `mq-gameover`, **Scale** `6`, `2` (the image is
96×32 pixels), **Z-Order** `55`, parked at (200, 310).
3. Give it this script, `GameOver`:
```text
OnUpdate ─▶ Branch( hp < 0.5 And started > 0.5 )
then ─▶ SetGlobal started = 0 (the hero and the slimes stop)
─▶ SetGlobal over = 1 (keeps the title card away)
─▶ SetVar overAt = Time
─▶ PlayAudio( SfxHurt )
─▶ Branch( GetVar overAt > 0.5 )
then ─▶ SetPosition2D( camera position ) (show the plaque)
─▶ Branch( Time > overAt + 2.5 ) then ─▶ LoadScene ""
```

```tgscript
//!tgscript v1
//! script name=GameOver
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetGlobal pos=(60,220) global=hp
const n2_value = ctx.getGlobal("hp");
//! node 3 GetGlobal pos=(60,320) global=started
const n3_value = ctx.getGlobal("started");
//! node 4 ConstNumber pos=(60,420)
const n4_value = 0.50;
//! node 5 Less pos=(260,220)
const n5_out = (n2_value < n4_value);
//! node 6 Greater pos=(260,320)
const n6_out = (n3_value > n4_value);
//! node 7 And pos=(460,260)
const n7_out = (n5_out && n6_out);
//! node 8 Time pos=(60,520)
const n8_value = ctx.time();
//! node 9 Branch pos=(660,80)
if (n7_out) {
//! node 10 ConstNumber pos=(660,240)
const n10_value = 0.00;
//! node 11 SetGlobal pos=(860,80) global=started
ctx.setGlobal("started", n10_value);
//! node 12 SetVar pos=(1060,80) var=overAt
ctx.setVar("overAt", n8_value);
//! node 13 FindEntity pos=(1060,240) entity=SfxHurt
const n13_value = ctx.findEntity("SfxHurt");
//! node 14 PlayAudio pos=(1260,80)
ctx.playAudio(n13_value);
//! node 15 ConstNumber pos=(1260,240)
const n15_value = 1.00;
//! node 16 SetGlobal pos=(1460,80) global=over
ctx.setGlobal("over", n15_value);
}
//! node 20 GetVar pos=(60,720) var=overAt
const n20_value = ctx.getVar("overAt");
//! node 21 Greater pos=(260,720)
const n21_out = (n20_value > n4_value);
//! node 22 Branch pos=(1460,80)
if (n21_out) {
//! node 23 FindEntity pos=(1460,240) entity=Camera
const n23_value = ctx.findEntity("Camera");
//! node 24 GetEntityPosition2D pos=(1660,240)
const n24_value = ctx.getEntityPosition2D(n23_value);
//! node 25 SetPosition2D pos=(1860,80)
ctx.setPosition2D(n24_value);
//! node 26 ConstNumber pos=(1660,360)
const n26_value = 2.50;
//! node 27 AddNumber pos=(1860,360)
const n27_out = (n20_value + n26_value);
//! node 28 Greater pos=(2060,320)
const n28_out = (n8_value > n27_out);
//! node 29 Branch pos=(2260,80)
if (n28_out) {
//! node 30 LoadScene pos=(2460,80) scene=""
ctx.loadScene("");
}
}
}
//! endregion
```
4. **Keep the title card away.** `started` is 0 again during GAME OVER, so `TitleScreen` would put
the title card back over the plaque. In `TitleScreen`, add **GetGlobal** `over`, **Less** (`0.5`)
and **And** them with the existing `started < 0.5` before its Branch.
5. **Quiet farmer on the title screen.** In `Farmer`, **And** the "near" check with
`started > 0.5`, so his bubble doesn't pop up over the title and Space on the title
doesn't hand you the sword.
**LoadScene** with an empty `scene` attribute reloads the scene that is running. In the editor it
restarts **Play**; in a published game it loads the scene again. Either way every global and
per-entity variable starts from zero, and **OnStart** gives the hero three hearts.
**Play**, press Space, and let the slimes win.
## Good practices
- **Freeze before you restart.** Setting `started` to 0 stops the hero and the slimes, because
their scripts already check it. The player sees what happened instead of being hit again.
- **Give the player a moment.** Two and a half seconds is enough to read GAME OVER and short enough
not to annoy. Make it a constant you can tune.
- **One flag per state.** `started` means "playing"; `over` means "showing GAME OVER". Reusing one
flag for both is how the title card ended up on top of the plaque.
- **Run the trigger once.** The first Branch fires only while `started` is 1, and it sets it to 0,
so `overAt` is stored once and the restart time doesn't move.
- **Restart with the scene, not by hand.** Resetting every coin, slime and variable by script is
long and easy to get wrong; reloading the scene resets everything you authored.
- **In the editor, LoadScene only restarts the open scene.** Loading a *different* scene from a
script works in a published game, but the editor refuses it so your open scene isn't replaced.
## This part's assets
[GameOver.tgscript](/downloads/meadow-quest/GameOver.tgscript) ·
[Health.tgscript](/downloads/meadow-quest/Health.tgscript) ·
[TitleScreen.tgscript](/downloads/meadow-quest/TitleScreen.tgscript) ·
[Farmer.tgscript](/downloads/meadow-quest/Farmer.tgscript) ·
[mq-gameover.png](/downloads/meadow-quest/mq-gameover.png) (the image with its `.mt`).
[Next: a main menu →](/rpg2d/15-main-menu/)
---
# 15. A main menu
URL: https://wiki.trisgine.com/rpg2d/15-main-menu/
Replace "press Space" with a real menu: a New Game button and a language picker, driven by the editor's built-in game-menu system.

The title card said "press Space". Now the game opens on a **menu** you can click: **New Game**
starts playing, and a dropdown switches the whole game between English and German.
> [!IMPORTANT]
> This part needs an editor from **18 October 2026 or later**. Attaching a script that uses **UiCommand** to a button should add **GameMenuModel** to the scene's systems (see the **Systems** tab). If it doesn't, your editor
> predates the feature; it arrives with the next editor update.
## How it works
The engine has a **game-menu system**, *GameMenuModel*. Buttons talk to it with a **UiCommand**
node, and it shows or hides UI elements by **name**:
| Element name | Shown when |
|---|---|
| `MainPage` | the menu is open (at the start) |
| `HudPage` | the game is running (after **New Game**) |
The `game.new` command switches from the menu to the game; the language picker uses
`setting.commit:ui.lang` and `settings.apply`. You only need to name your panels right; the system
is added to the scene by itself as soon as a UI script uses **UiCommand**.
## How to build it
1. **A logo without "press Space".** Paint `mq-logo.png` (96×48, the title card with *A TINY RPG*
underneath), or import it from [this part's assets](#this-parts-assets). Select `Title` and
click its image slot to pick `mq-logo.png`.
2. **TitleScreen no longer starts the game.** Delete its **ActionPressed** *Jump* Branch and the
nodes in it, and give the remaining Branch an `else` that parks the logo at (200, 240):
```tgscript
//!tgscript v1
//! script name=TitleScreen
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetGlobal pos=(260,120) global=started
const n2_value = ctx.getGlobal("started");
//! node 3 ConstNumber pos=(260,240)
const n3_value = 0.50;
//! node 4 Less pos=(460,120)
const n4_out = (n2_value < n3_value);
//! node 20 GetGlobal pos=(260,340) global=over
const n20_value = ctx.getGlobal("over");
//! node 21 Less pos=(460,340)
const n21_out = (n20_value < n3_value);
//! node 22 And pos=(460,220)
const n22_out = (n4_out && n21_out);
//! node 5 Branch pos=(660,80)
if (n22_out) {
//! node 6 FindEntity pos=(660,260) entity=Camera
const n6_value = ctx.findEntity("Camera");
//! node 7 GetEntityPosition2D pos=(860,260)
const n7_value = ctx.getEntityPosition2D(n6_value);
//! node 8 SetPosition2D pos=(1060,80)
ctx.setPosition2D(n7_value);
} else {
//! node 9 ConstVec2 pos=(860,400)
const n9_value = ctx.vec2(200.00, 240.00);
//! node 10 SetPosition2D pos=(1060,240)
ctx.setPosition2D(n9_value);
}
}
//! endregion
```
3. **The menu page.** Select `MeadowHud`, then **UI > Panel**. Rename it `MainPage`, pick the
**stretch** anchor preset, and give it a dark tint with **A** about `0.35`, so the meadow shows
through.
4. **The button.** With `MainPage` selected, **UI > Button**. Rename it `MenuNewGame`; **center**
anchor preset, **Pos Y** `250`, **Width** `440`, **Height** `76`. Set its label's text to
`@menu.newgame`, a key the engine already translates ("New Game", "Neues Spiel").
5. **The language picker.** With `MainPage` selected, **UI > Dropdown**. Rename it `OptLanguage`;
**center**, **Pos Y** `345`, **Width** `440`, **Height** `64`. Its list needs exactly two items,
**English first**, then **Deutsch**, with the texts `@opt.lang.en` and `@opt.lang.de`: the menu
system maps the first item to `en` and the second to `de`.
6. **The scripts.** Create these two and put each in its element's **Script** slot in the Inspector:
`MenuPlay`, on `MenuNewGame`: when clicked, start the game and switch the menu to the game page.
```tgscript
//!tgscript v1
//! script name=MenuPlay
//! region graph
//! node 1 OnUiEvent pos=(60,80)
export function onUiEvent(ctx) {
//! node 2 UiClicked pos=(60,200)
const n2_value = ctx.uiClicked();
//! node 3 Branch pos=(260,80)
if (n2_value) {
//! node 4 ConstNumber pos=(260,240)
const n4_value = 1.00;
//! node 5 SetGlobal pos=(460,80) global=started
ctx.setGlobal("started", n4_value);
//! node 6 UiCommand pos=(660,80) command="game.new"
ctx.uiCommand("game.new");
}
}
//! endregion
```

`MenuLanguage`, on `OptLanguage`: when a language is picked, commit and apply it.
```tgscript
//!tgscript v1
//! script name=MenuLanguage
//! region graph
//! node 1 OnUiEvent pos=(60,80)
export function onUiEvent(ctx) {
//! node 2 UiValueCommitted pos=(60,200)
const n2_value = ctx.uiValueCommitted();
//! node 3 Branch pos=(260,80)
if (n2_value) {
//! node 4 UiCommand pos=(460,80) command="setting.commit:ui.lang"
ctx.uiCommand("setting.commit:ui.lang");
//! node 5 UiCommand pos=(660,80) command="settings.apply"
ctx.uiCommand("settings.apply");
}
}
//! endregion
```
**Play**: the menu opens over the meadow. Pick **Deutsch** and every key-based text switches at once;
click **Neues Spiel** and the menu gives way to the game. When you lose, the restart brings you back
to the menu.

## Good practices
- **Names are the contract.** The menu system finds `MainPage`, `HudPage`, `MenuNewGame` and
`OptLanguage` by name. Rename one and it silently stops being managed.
- **Everything shown during play goes inside `HudPage`.** The quest line from Part 13 already lives
there, so it stays hidden on the menu without a single extra node.
- **The menu changes pages; your scripts change the game.** `game.new` doesn't load a scene or set
your variables. `MenuPlay` sets `started` itself, and every gameplay script already waits for it.
- **Use keys for menu text.** `@menu.newgame` comes translated; a literal "New Game" would stay
English in every language. [Part 16](/rpg2d/16-languages/) adds keys of your own.
- **Make the menu readable over the game.** A dark, see-through page keeps the world visible and
the buttons legible.
> [!NOTE]
> Known issue: after a restart the language picker shows *English* even when German is still
> active. Picking a language again fixes the label; a fix is on the way.
## This part's assets
[MenuPlay.tgscript](/downloads/meadow-quest/MenuPlay.tgscript) ·
[MenuLanguage.tgscript](/downloads/meadow-quest/MenuLanguage.tgscript) ·
[TitleScreen.tgscript](/downloads/meadow-quest/TitleScreen.tgscript) ·
[MeadowHud.uidoc](/downloads/meadow-quest/MeadowHud.uidoc) ·
[mq-logo.png](/downloads/meadow-quest/mq-logo.png) (the image with its `.mt`).
[Next: languages →](/rpg2d/16-languages/)
---
# 16. Languages
URL: https://wiki.trisgine.com/rpg2d/16-languages/
Translate the quest line into German with your own localization keys, a CSV round trip through the Localization panel, and a separate number element.

The menu already switches the engine's own words. Now the quest line follows: in German it says
*Sprich mit dem Bauern* and *Schleime übrig: 2*.
> [!IMPORTANT]
> This part needs an editor from **18 October 2026 or later**. In **Windows > Localization**, **Import CSV…** should open your browser's file chooser. If it doesn't, your editor
> predates the feature; it arrives with the next editor update.
## How it works
- A UI text that starts with `@` is a **key**: `@quest.talk` shows the active language's text for
`quest.talk`. **SetText** accepts keys too.
- Each language is one table: `en.tgloc`, `de.tgloc`. **English is the master list**; a key missing
in German falls back to English.
- You edit tables as **CSV** (`key,en,de`) in any spreadsheet, round trip through the
**Localization** panel.
## How to add the keys
1. **Windows > Localization**. Under *Active language* keep **en**, and under *Compare with* click
**de**, so both languages are in the grid.
2. Click **Export CSV**. The browser downloads `export.csv` with every key the project has.
3. Open it in a spreadsheet and add these rows at the end. Save it as **CSV, UTF-8**.
| key | en | de |
|---|---|---|
| `quest.chest` | Open the chest! | Öffne die Truhe! |
| `quest.coins` | Coins to find: | Münzen übrig: |
| `quest.slimes` | Slimes left: | Schleime übrig: |
| `quest.talk` | Talk to the farmer | Sprich mit dem Bauern |
| `quest.title` | Meadow Quest | Meadow Quest |
| `quest.won` | You did it! | Geschafft! |
4. Tick **All columns**, click **Import CSV…** and pick the file. The status line confirms
*Wrote 80 rows to en, de… reloaded en*, and the new keys appear in the grid.

> [!WARNING]
> An import **replaces** each language's whole table with the file's column. Always start from
> **Export CSV** and add to it: importing just the six rows would delete every other key, the menu's
> included.
## How to use them
**SetTextNumber**'s prefix is plain text, never a key, so the number gets its own element:
1. In `QuestPanel`, change `QuestText` to the **middle-left** anchor preset, **Pos X** `24`,
**Width** `500`, **Height** `48`, left-aligned, text `@quest.title`.
2. Add a second **UI > Text**, `QuestCount`: **middle-right**, **Pos X** `-24`, **Width** `80`,
right-aligned, text a single space.
3. Rewrite `Quest`: **SetText** writes keys into `QuestText`, and **SetTextNumber** with an empty
prefix writes the count into `QuestCount` (other lines clear it with a space).
```tgscript
//!tgscript v1
//! script name=Quest
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 FindEntity pos=(60,220) entity=QuestText
const n2_value = ctx.findEntity("QuestText");
//! node 40 FindEntity pos=(60,320) entity=QuestCount
const n40_value = ctx.findEntity("QuestCount");
//! node 3 GetGlobal pos=(60,420) global=hasSword
const n3_value = ctx.getGlobal("hasSword");
//! node 4 GetGlobal pos=(60,520) global=slain
const n4_value = ctx.getGlobal("slain");
//! node 5 GetGlobal pos=(60,620) global=coins
const n5_value = ctx.getGlobal("coins");
//! node 6 GetGlobal pos=(60,720) global=won
const n6_value = ctx.getGlobal("won");
//! node 7 ConstNumber pos=(60,820)
const n7_value = 0.50;
//! node 8 ConstNumber pos=(60,920)
const n8_value = 2.00;
//! node 9 ConstNumber pos=(60,1020)
const n9_value = 3.00;
//! node 30 GetGlobal pos=(60,1120) global=started
const n30_value = ctx.getGlobal("started");
//! node 10 Less pos=(260,420)
const n10_out = (n3_value < n7_value);
//! node 11 Less pos=(260,520)
const n11_out = (n4_value < n8_value);
//! node 12 Less pos=(260,620)
const n12_out = (n5_value < n9_value);
//! node 13 Less pos=(260,720)
const n13_out = (n6_value < n7_value);
//! node 31 Less pos=(260,1120)
const n31_out = (n30_value < n7_value);
//! node 32 Branch pos=(460,80)
if (n31_out) {
//! node 33 SetText pos=(660,80) text="@quest.title"
ctx.setText("@quest.title", n2_value);
//! node 34 SetText pos=(860,80) text=" "
ctx.setText(" ", n40_value);
} else {
//! node 14 Branch pos=(660,240)
if (n10_out) {
//! node 15 SetText pos=(860,240) text="@quest.talk"
ctx.setText("@quest.talk", n2_value);
//! node 35 SetText pos=(1060,240) text=" "
ctx.setText(" ", n40_value);
} else {
//! node 16 Branch pos=(860,400)
if (n11_out) {
//! node 41 SetText pos=(1060,400) text="@quest.slimes"
ctx.setText("@quest.slimes", n2_value);
//! node 17 SubNumber pos=(1060,560)
const n17_out = (n8_value - n4_value);
//! node 18 SetTextNumber pos=(1260,400) prefix=""
ctx.setTextNumber("", n40_value, n17_out);
} else {
//! node 19 Branch pos=(1060,720)
if (n12_out) {
//! node 42 SetText pos=(1260,720) text="@quest.coins"
ctx.setText("@quest.coins", n2_value);
//! node 20 SubNumber pos=(1260,880)
const n20_out = (n9_value - n5_value);
//! node 21 SetTextNumber pos=(1460,720) prefix=""
ctx.setTextNumber("", n40_value, n20_out);
} else {
//! node 22 Branch pos=(1260,1040)
if (n13_out) {
//! node 23 SetText pos=(1460,1040) text="@quest.chest"
ctx.setText("@quest.chest", n2_value);
//! node 36 SetText pos=(1660,1040) text=" "
ctx.setText(" ", n40_value);
} else {
//! node 24 SetText pos=(1460,1200) text="@quest.won"
ctx.setText("@quest.won", n2_value);
//! node 37 SetText pos=(1660,1200) text=" "
ctx.setText(" ", n40_value);
}
}
}
}
}
}
//! endregion
```
**Play**, pick **Deutsch**, click **Neues Spiel**, and walk to the farmer.
## Good practices
- **Export, add, import.** Never build a CSV from scratch for a project that already has keys.
- **Name keys by place and purpose** (`quest.talk`, `menu.newgame`), never by their English
wording: the English can change, the key shouldn't.
- **Keep numbers out of sentences.** Word order differs between languages ("2 slimes left" /
"noch 2 Schleime"); a separate number element, or a key per phrasing, keeps grammar right.
- **Leave room.** German is often a third longer than English. The quest panel is 640 wide for
that reason.
- **Painted text stays in one language.** The farmer's speech bubbles are pixel art, so they stay
English (you can see it in the picture above). For dialogue in several languages, use UI text
with keys.
- **The in-game picker offers English and German.** Other languages you import can be previewed
in the Localization panel's *Active language* buttons.
## This part's assets
[Quest-languages.tgscript](/downloads/meadow-quest/Quest-languages.tgscript) (this part's `Quest`; the
pack's own `Quest.tgscript` keeps the English text so it works before you import the keys) ·
[MeadowHud.uidoc](/downloads/meadow-quest/MeadowHud.uidoc)
The six rows as a CSV: [meadow-quest-rows.csv](/downloads/meadow-quest/meadow-quest-rows.csv)
(paste them into your export; don't import this file on its own).
[Next: what's next →](/rpg2d/12-whats-next/)
---
# What's next
URL: https://wiki.trisgine.com/rpg2d/12-whats-next/
Ideas to extend Meadow Quest, and what visual scripting can't do yet but soon will.
## Ideas
- **More enemies**: duplicate a slime. Make one faster by raising the `1.8` in its script, or
give it more health with a per-entity variable it counts down before it's defeated.
- **A key and a locked door**: pick up a key like a coin (a global `hasKey`), show it in a sixth
inventory slot, and make a second gate test it.
- **A shop**: a second NPC whose bubble offers a potion; pressing Space near it trades 1 coin
(`coins` − 1) for a potion (`potions` + 1).
- **Bigger world**: widen the map (Tilemap **Resize…**), add rooms, and update the camera clamp.
- **A score**: a second UI Text with **SetTextNumber** `Score: ` and a global that coins and
slimes add to.
- **Footsteps and music changes**: a quiet looping Audio Source started with **PlayAudio** while
the hero moves and stopped with **StopAudio** when it stands still.
- **An options page**: the game-menu system also knows `page:Options` with volume sliders and
graphics settings; build an `OptionsPage` panel and a button that sends `page:Options`.
- **Gamepad**: plug one in. *Move* is the left stick and *Jump* (talk, start, swing) is the
bottom button.
Useful nodes not used yet: `Every` (fires every N seconds), `Random` / `RandomRange`,
`SendMessage` / `OnMessage` (one entity telling another to do something), `CameraFollow2D` (a
smoothed camera follow in one node), `Raycast2D` and `OverlapCircle2D` (asking physics what is
in a line or an area), and `OnCollisionEnter` for solid hits (tick **Reports collisions** on a
Physics Body 2D).
## Not possible yet (and what's coming)
| Wanted | Today | Coming |
|---|---|---|
| spawn or remove entities | move things far away instead | **spawn & destroy** are in development |
| a second level | **LoadScene** works in a published game; the editor only restarts the open scene | |
| scene-wide zero gravity | set **Gravity scale** 0 per body | a scene physics setting is requested |
## Hand it to an AI
Everything in this guide is plain text underneath: the scripts above, and the scene, which the
editor saves as a `.tgscene`. See [Working with AI](/ai/overview/) to have an agent build or
extend it.
The complete game is downloadable as [meadow-quest.zip](/downloads/meadow-quest.zip). In the
editor tab's developer console, [agent-build-2d.js](/downloads/meadow-quest/agent-build-2d.js)
imports and opens it in one step.
---
# The Village Gate: overview
URL: https://wiki.trisgine.com/rpg/overview/
Build a small first-person RPG in about an hour, using nothing but the web editor.

In this tutorial you'll make **The Village Gate**, a tiny first-person adventure:
- You arrive at a small village on a grassy plain.
- An orange **villager** stands outside a stone house. Walk up to them and they hop to greet you.
- A wooden **fence** with a **gate** blocks the way north. Approach the gate and it rises open.
- Behind it, three spinning **golden coins** wait. Walk into one to collect it.
- A title card on screen tells you what to do.
Everything happens in the browser editor at [editor.trisgine.com](https://editor.trisgine.com):
painting textures, placing objects, wiring the logic as node graphs, adding the HUD, and
play-testing. You don't install anything or write C++.
## What you'll learn
| Part | You learn |
|---|---|
| [1. Set up the project](/rpg/1-setup/) | importing files, opening a scene, playing first-person |
| [2. Paint a coin](/rpg/2-paint-a-coin/) | the Pixel Art editor, textures, materials |
| [3. Build the village](/rpg/3-build-the-village/) | creating, moving, scaling, duplicating and colouring objects |
| [4. Collectible coins](/rpg/4-collectible-coins/) | your first visual script: distance check → branch → action |
| [5. The gate](/rpg/5-the-gate/) | reusing the pattern with different numbers |
| [6. The villager](/rpg/6-the-villager/) | `then` / `else` branches |
| [7. Title & HUD](/rpg/7-title-and-hud/) | screen UI canvases and text |
| [8. Polish & share](/rpg/8-polish-and-share/) | sky, sound, saving, sharing, and where to go next |
## Why first-person?
Honest answer: it's what the engine can make **playable** from the web editor today.
First-person movement is built in (`FreeLookCamera`), and visual scripts can react to how far
away the player is. A classic top-down 2D RPG needs two things that haven't shipped yet:
keyboard-driven 2D sprites, and scripts that react to collisions. The [2D pages](/2d/sprites/)
cover what *does* work in 2D.
## The download pack
Everything the tutorial needs that isn't made inside the editor: four small pixel-art textures
(with their `.mt` sidecars, so their UUIDs match the scene), a starter scene, and, if you get
stuck, the finished scripts and the complete scene.
| File | What |
|---|---|
| [tiny-rpg.zip](/downloads/tiny-rpg.zip) | everything below in one archive |
| [VillageStarter.tgscene](/downloads/tiny-rpg/VillageStarter.tgscene) | the world without any logic: your starting point |
| [rpg-grass.png](/downloads/tiny-rpg/rpg-grass.png) · [.mt](/downloads/tiny-rpg/rpg-grass.png.mt) | ground |
| [rpg-stone.png](/downloads/tiny-rpg/rpg-stone.png) · [.mt](/downloads/tiny-rpg/rpg-stone.png.mt) | house walls |
| [rpg-wood.png](/downloads/tiny-rpg/rpg-wood.png) · [.mt](/downloads/tiny-rpg/rpg-wood.png.mt) | fence and gate |
| [rpg-white.png](/downloads/tiny-rpg/rpg-white.png) · [.mt](/downloads/tiny-rpg/rpg-white.png.mt) | plain surface to tint |
| [VillageCoin](/downloads/tiny-rpg/VillageCoin.tgscript) · [Gate](/downloads/tiny-rpg/Gate.tgscript) · [Villager](/downloads/tiny-rpg/Villager.tgscript) `.tgscript` | the finished scripts |
| [VillageComplete.tgscene](/downloads/tiny-rpg/VillageComplete.tgscene) | the finished scene, with scripts attached |
> [!NOTE]
> The scripts, the download pack and the trigger distances were checked in the live web
> editor. If a step doesn't match what you see, please
> [report it](https://gitlab.trisgram.com/trisgram/trisgine-wiki/-/issues).
Ready? [Set up the project →](/rpg/1-setup/)
---
# 1. Set up the project
URL: https://wiki.trisgine.com/rpg/1-setup/
Import the textures and the starter scene, open it, and take a first walk.
## Download the pack
Download [tiny-rpg.zip](/downloads/tiny-rpg.zip) and unzip it somewhere you can find it.
## Import the textures
1. Open [editor.trisgine.com](https://editor.trisgine.com).
2. In the **Project** panel, double-click the **Textures** folder if you have one. Otherwise
stay in **Assets**; the folder doesn't matter, only the UUIDs do.
3. Choose **Assets > Import…** and select the **eight texture files**: the four `.png` files
**and** their four `.png.mt` sidecars.
You can also drag all eight from your file manager and drop them onto the editor.
The `.mt` sidecars carry each texture's UUID (`7A11C0DE00000001` to `…04`). Import them
together with the images, and the starter scene will find them.
## Import and open the starter scene
1. In the Project panel, go to `Assets/Scenes` (if you don't have it yet, stay in `Assets`).
2. **Assets > Import…**, then `VillageStarter.tgscene`.
3. **Double-click** `VillageStarter` in the Project panel to open it.
You should see grass, a grey stone house, an orange capsule (the villager), a wooden fence
with a gate in the middle, and three small yellow cubes behind it.
> [!NOTE]
> If some surfaces look plain white, the textures were still decoding when the scene opened.
> **File > Reload Current Scene** fixes it.
## Take a walk
1. Press **▶ Play**.
2. **Move the mouse over the Simulation panel.** The player only listens while it's there.
3. Walk with W A S D and look around with the mouse.
Hold Shift to run. Esc gives you the mouse cursor back.
4. Press **■ Stop**. You're back at the start.
Nothing reacts yet: the coins don't collect, the gate doesn't open, the villager ignores you.
You'll fix all of that with scripts.
## What's in the starter scene?
Open the Hierarchy: **Player**, **Sun**, **Ground**, **House**, **Villager**,
**FenceLeft**, **FenceRight**, **Gate**, **Coin1–3**. Click each one and look at its
Inspector.
The scene file itself is plain text. This is the top of it:
```tgscene
configs:
update:
-MoveByVelocity
-RotateByAngularVelocity
-DistanceToPlayerSquare
-ScriptRun
-WorldMatrix
input:
-FreeLookCamera
render:
-ViewMatrix
-ShadowRendering
-SortedSubmissionRendering
-SkyboxRendering
entities:
-Player:
-PerspectiveCamera:60
-Position:0,1.6,-14
-Rotation:0
-Rotation2D:0,0
-Color:0.45,0.65,0.9
-PlayerTag
-PlayerInputTag
-Gate:
-Material:EAF81A2663BA92E,7A11C0DE00000003,0.6,0.4,0.25
-Primitive:Cube,4,3,0.4
-Position:0,1.5,6
-Rotation:0
-Scale:1
```
- `update:` and `input:` list the **systems** that run every frame, in order.
**FreeLookCamera** is what makes the player walk. **DistanceToPlayerSquare** works out how
far each object is from you, and **ScriptRun**, which comes *after* it, will run your scripts.
- `Player` is the camera you look through: the `PlayerTag` / `PlayerInputTag` tags mark it.
- `Gate` is a 4 × 3 × 0.4 box, textured with wood (`…03`) and tinted brown.
The full format is in the [scene format reference](/reference/scene-format/).
[Next: paint a coin →](/rpg/2-paint-a-coin/)
---
# 2. Paint a coin
URL: https://wiki.trisgine.com/rpg/2-paint-a-coin/
Draw a 16×16 coin in the Pixel Art editor and put it on the coin cubes.

The coins are plain yellow right now. Let's give them a proper pixel-art face.
## Paint it
1. **Windows > Pixel Art**.
2. It opens with an empty 32 × 32 canvas, which is all you need. (**New**, the first toolbar
icon, starts another one at a size you choose.)
3. Pick a bright gold in the colour picker (for example hex `FFCC1A`), choose the
**Rectangle** tool, switch on *filled*, and drag a square from (10, 10) to (21, 21).
4. Pick a darker gold (`BF800D`), switch *filled* off, and draw the same rectangle again as an
outline.
5. Optional: a lighter pixel or two in the top-left corner makes it shine.
## Save it as a texture
Use **Save As** and pick a flat **.png** format (not *Layered .tgpx*). Name it `coin.png`, and save it into
`Assets/Textures` if you have that folder. The status line confirms:
*Saved Flattened image (.png) to Assets/Textures/coin.png*. The texture now has a UUID.
## Put it on the coins
1. Click **Coin1** in the Hierarchy.
2. In the Inspector, open **Material > Main Maps** and click the **Albedo** slot (it reads
`rpg-white.png`).
3. Pick `coin.png`.
4. Check **Surface > Base Color**. The coin has a yellow tint on top of the texture. Set it to
white if you want to see your pixels exactly as painted.
5. Do the same for **Coin2** and **Coin3**.

> [!TIP]
> Want to change the art later? Reopen `coin.png` in Pixel Art (double-click it in the
> Project panel), paint, and save. Every material using it updates immediately.
## Optional: make it with AI
If you've [set up AI generation](/ai/pixel-art-generation/), type something like
*"golden coin, pixel art, single item, centred, plain background"* in the prompt field
under the canvas and press **Generate**. Turn on **Remove background**.
[Next: build the village →](/rpg/3-build-the-village/)
---
# 3. Build the village
URL: https://wiki.trisgine.com/rpg/3-build-the-village/
Add more buildings, a well and a lantern with primitives, and practise moving, scaling and colouring.
The starter village is sparse on purpose. This part is free-form practice; nothing later
depends on it. Make it yours.

## A second house
1. Right-click the **House** in the Hierarchy and choose **Duplicate** (Ctrl+D).
2. With the copy selected, press W and drag it to the other side of the path,
or type a position in **Transform**, for example `7, 1.5, -2`.
3. Right-click it, choose **Rename** (F2), and call it `HouseEast`.
## A roof
1. Right-click empty Hierarchy space and choose **Add Mesh > Wedge**.
2. Scale it (R, or the **Scale** fields) to match the house's footprint, and move it
on top. If it faces the wrong way, rotate it 90° around Y.
3. Under **Material > Surface > Base Color**, pick a dark red.
## A doorway (CSG)
Primitives can cut holes in each other:
1. Add a **Cube** and scale it to door size, for example `1.2 × 2 × 1`.
2. Move it so that it pokes through the house wall at ground level.
3. Right-click the door cube, then **CSG > Make Subtract**. Right-click the house, then
**CSG > Make Receiver (Add)**.
4. The house now has a doorway. **CSG > Apply** bakes it into one mesh.
## A well and a lantern
- **Well**: **Add Mesh > Cylinder**, scaled to `1.5 × 1 × 1.5`, with the stone texture
(Material > Albedo: `rpg-stone.png`).
- **Lantern**: **Light > Point Light** (if your editor build has it), placed by the gate.
Give it a warm colour in the Inspector.
## Tips
- F frames the selection; right mouse + WASD flies.
- Hold Ctrl while dragging to snap.
- Ctrl+Z undoes anything. The Edit menu shows what will be undone.
- Keep new things **south of the fence** (negative Z) and **away from the coins**. The scripts
in the next parts use fixed positions.
> [!WARNING]
> The player has **no collision**: you can walk through houses, and off the edge of the
> ground. Think of walls and fences as signposts, not barriers.
**Save** (Ctrl+S) before moving on.
[Next: collectible coins →](/rpg/4-collectible-coins/)
---
# 4. Collectible coins
URL: https://wiki.trisgine.com/rpg/4-collectible-coins/
Your first visual script. When the player gets within 2 metres, the coin vanishes.

## The idea
Every frame, each coin asks: *"Is the player closer than 2 m?"* If so, it moves itself 50 m
underground, out of sight. That's "collected".
As a graph:
```text
OnUpdate ──▶ Branch ──then──▶ SetPosition( 0, −50, 0 )
▲
Greater( 4 , DistanceToPlayerSquare )
```
`DistanceToPlayerSquare` is the distance **squared**, so 2 m becomes 2 × 2 = **4**.
## Build it with nodes
1. **Windows > Script Editor**, then **New**. Name it `VillageCoin`. The editor creates
`Assets/Scripts/VillageCoin.tgscript` with a starter graph.
2. Select all the starter nodes and delete them, keeping only **OnUpdate**.
3. Press Space, search for **GetNumber**, and add it. In its attribute field, enter
`DistanceToPlayerSquare`.
4. Add a **ConstNumber** and set it to `4`.
5. Add **Greater**. Wire **ConstNumber → a** and **GetNumber → b**. It now answers "4 > distance²".
6. Add **Branch**. Wire OnUpdate's white exec output to Branch's input, and **Greater → condition**.
7. Add **ConstVec3** = `0, -50, 0`, and **SetPosition**. Wire Branch's **then** to SetPosition,
and ConstVec3 to SetPosition's **value**.
8. **Compile**. The status should read *compiles (1 handler)*. Then **Save**.
## …or paste it as text
Switch the Script Editor to the **Text** tab, select everything, and paste:
```tgscript
//!tgscript v1
//! script name=VillageCoin
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetNumber pos=(260,80) component=DistanceToPlayerSquare
const n2_value = ctx.getNumber("DistanceToPlayerSquare");
//! node 3 ConstNumber pos=(260,200)
const n3_value = 4.00;
//! node 4 Greater pos=(460,120)
const n4_out = (n3_value > n2_value);
//! node 5 Branch pos=(660,80)
if (n4_out) {
//! node 6 ConstVec3 pos=(660,240)
const n6_value = ctx.vec3(0.00, -50.00, 0.00);
//! node 7 SetPosition pos=(860,80)
ctx.setPosition(n6_value);
}
}
//! endregion
```
Switch back to **Graph**, and the same seven nodes are there, wired. **Compile**, **Save**.
## Attach it to the coins
1. Select **Coin1** in the Hierarchy.
2. In the Inspector, scroll to **Script**, click the *(none)* slot, and pick **VillageCoin.tgscript**.
3. Repeat for **Coin2** and **Coin3**. One script serves all three.
4. **Save the scene**.
## Play-test
Press **Play**, put the mouse over the Simulation panel, and walk north through the gate
(it's still closed, but you can walk through it for now). Walk into a coin. It disappears.
When we tested this, a coin vanished once the player came within about 1.6 m: the camera
is at eye height (1.6 m) and the coin at 0.8 m, so part of the 2 m is vertical.
Press **Stop**, and all coins come back.
> [!IMPORTANT]
> **Did every coin vanish the instant you pressed Play?** Then `ScriptRun` is listed
> *before* `DistanceToPlayerSquare` in the scene's `update:` list, so on the first frame the
> distance still reads 0. The starter scene already has the right order; keep it that way if
> you edit the scene file.
[Next: the gate →](/rpg/5-the-gate/)
---
# 5. The gate
URL: https://wiki.trisgine.com/rpg/5-the-gate/
Reuse the coin pattern so the gate swings up out of the way when you approach.
The gate uses the same pattern as the coin, with two different numbers:
| | VillageCoin | Gate |
|---|---|---|
| trigger radius | 2 m → `4` | 5 m → `25` |
| where it goes | `0, -50, 0` (underground) | `0, 4.6, 6` (raised above the fence) |
The gate stands at `0, 1.5, 6`. Raising it to `y = 4.6` lifts its 3 m height clear of the
path, so it looks like a portcullis that has opened.
## Make the script
**Script Editor > New**, name it `Gate`, then in the **Text** tab:
```tgscript
//!tgscript v1
//! script name=Gate
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetNumber pos=(260,80) component=DistanceToPlayerSquare
const n2_value = ctx.getNumber("DistanceToPlayerSquare");
//! node 3 ConstNumber pos=(260,200)
const n3_value = 25.00;
//! node 4 Greater pos=(460,120)
const n4_out = (n3_value > n2_value);
//! node 5 Branch pos=(660,80)
if (n4_out) {
//! node 6 ConstVec3 pos=(660,240)
const n6_value = ctx.vec3(0.00, 4.60, 6.00);
//! node 7 SetPosition pos=(860,80)
ctx.setPosition(n6_value);
}
}
//! endregion
```
**Compile**, **Save**, then select **Gate** in the Hierarchy and pick `Gate.tgscript` in its
**Script** slot. Save the scene.
> [!TIP]
> Faster: in the Project panel, select `VillageCoin.tgscript` and **Duplicate** it
> (Ctrl+D), open the copy, and change just the two constants in the graph.

## Play-test
Walk towards the gate. In our test it rose when the player was about 4.4 m away, and it stays
open, because nothing ever moves it back down. Press **Stop** to reset it.
## Why absolute positions?
`SetPosition` sets *where the object is*, not *how far to move it*. So the target is written
out in full: `0, 4.6, 6` keeps the gate's own x and z. If you moved the gate in Part 3,
update the constant to match.
A smoother gate is possible: instead of `SetPosition`, use `SetVelocity` to make it slide
upward. You'd then need a second check to stop it, comparing its height with a limit, and
scripts can't yet pull the `y` out of a vector. Teleporting is the honest simple version.
[Next: the villager →](/rpg/6-the-villager/)
---
# 6. The villager
URL: https://wiki.trisgine.com/rpg/6-the-villager/
A Branch with both "then" and "else", so the villager hops up when you're near and settles back when you leave.
The coin and the gate only ever react **once**. The villager should react *while* you're
near and stop when you walk away, so we use both of the Branch's outputs.
```text
┌─then──▶ SetPosition( -3, 1.6, -4 ) (on tiptoe)
OnUpdate ──▶ Branch ──┤
└─else──▶ SetPosition( -3, 1.0, -4 ) (feet on the ground)
condition: 16 > DistanceToPlayerSquare (within 4 m)
```
## Make the script
**Script Editor > New**, name it `Villager`, and paste into **Text**:
```tgscript
//!tgscript v1
//! script name=Villager
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 GetNumber pos=(260,80) component=DistanceToPlayerSquare
const n2_value = ctx.getNumber("DistanceToPlayerSquare");
//! node 3 ConstNumber pos=(260,200)
const n3_value = 16.00;
//! node 4 Greater pos=(460,120)
const n4_out = (n3_value > n2_value);
//! node 5 Branch pos=(660,80)
if (n4_out) {
//! node 6 ConstVec3 pos=(660,240)
const n6_value = ctx.vec3(-3.00, 1.60, -4.00);
//! node 7 SetPosition pos=(860,40)
ctx.setPosition(n6_value);
} else {
//! node 8 ConstVec3 pos=(660,360)
const n8_value = ctx.vec3(-3.00, 1.00, -4.00);
//! node 9 SetPosition pos=(860,200)
ctx.setPosition(n8_value);
}
}
//! endregion
```
In the **Graph** tab, the Branch now has wires leaving from both **then** and **else**.
Compile, Save, then attach `Villager.tgscript` to **Villager**. Save the scene.

## Play-test
Walk up the path. About 4 m from the villager (we measured it starting at 6.9 m out along the
path, which is about 4 m in a straight line), they pop up 0.6 m. Back away and they drop back
down.
## Ideas to try
- Make the villager hop higher, or lower the trigger radius to `9` (3 m).
- Give the house's door a "creak open" with the same then/else trick.
- Duplicate the villager, move the copy, and remember that the script has the position written
into it. You'll need a second script with the new numbers.
> [!NOTE]
> We first tried making the villager **spin** by writing to its *Angular Velocity* from the
> script. In our tests that had no visible effect, so stick to `SetPosition` / `SetVelocity`
> for movement for now.
[Next: title & HUD →](/rpg/7-title-and-hud/)
---
# 7. Title & HUD
URL: https://wiki.trisgine.com/rpg/7-title-and-hud/
Put the quest on screen with a UI canvas and a text element.

## Add a screen canvas
1. Right-click empty space in the Hierarchy, then **UI > Canvas (Screen)**. A **Canvas** entity
appears and is selected.
2. With the canvas still selected, right-click again, then **UI > Text**. A **Text** entity
appears under the canvas.
## Write the quest
Select **Text** and, in the Inspector:
1. Under **UI Element**, click the **top-centre** square in the anchor preset grid, so the text
sticks to the top of the screen.
2. Set **Width** to `900` and **Height** to `60`, and **Pos Y** to `-40` to move it down a little
from the edge.
3. Scroll to **Text Style**. In the text box at the top of that section, type:
`Greet the villager, pass the gate, find the three golden coins.`
and press Enter. The text only applies when you press Enter.
4. Set **Size** to `32` and **Align** to *Center*.
## A title panel (optional)
Add **UI > Panel** under the canvas, anchor it to the centre, give it a dark, semi-transparent
**Tint**, and put a large **Text** reading *The Village Gate* inside it.
Save the scene. Saving also writes the canvas to a `.uidoc` file next to it.
## Play-test
Press **Play**: the quest line sits over the game view.
> [!TIP]
> The HUD can **count** the coins too: a script with **FindEntity** (the text element's name)
> and **SetTextNumber** writes a prefix and a number into it. The 2D tutorial's
> [quest line](/rpg2d/13-quest-text/) shows how.
[Next: polish & share →](/rpg/8-polish-and-share/)
---
# 8. Polish & share
URL: https://wiki.trisgine.com/rpg/8-polish-and-share/
Sky, fog and sound, saving properly, sharing your village, and ideas for what to build next.
## Mood: sky, fog, light
Click **Settings** at the top of the Hierarchy:
- **Sky (day/night)**: set a late-afternoon time of day for long shadows.
- **Fog**: a light blue-grey fog hides the edge of the world.
- **Post-process**: try ambient occlusion and anti-aliasing.
The **Sun** entity's direction controls the shadows. Select it and turn it.
## Sound
1. Import a gentle loop (birds, wind) as `.ogg` or `.wav`. Sites like
[freesound.org](https://freesound.org) have CC0 sounds.
2. Right-click the Hierarchy, then **Audio Source**. Put it by the house.
3. In the Inspector: pick the clip, **Gain** `0.6`, **AttMin** `2`, **AttMax** `30`, tick **Loop**.
You'll hear it grow louder as you walk towards the house. (Click the page once if the browser
is holding audio back.)
## Save, and keep a copy
- Ctrl+S, then check that the orange **Unsaved** pill is gone.
- Your village lives in this browser only (see [Saving & storage](/editor/saving-and-storage/)).
Keep the tutorial pack and your own source files on disk.
## Sharing
There's no "publish" button in the web editor yet. To give your village to a friend:
1. Send them the **tutorial pack** (or your own textures **with their `.mt` files**).
2. Send your `VillageCoin`, `Gate` and `Villager` scripts. In the Script Editor, use the **Text** tab
and copy each one into a `.tgscript` file.
3. Send the scene. The finished reference version is
[VillageComplete.tgscene](/downloads/tiny-rpg/VillageComplete.tgscene).
They import the textures, then the scripts **into `Assets/Scripts`** (the scene refers to them
by that path; create any script there first with **Script Editor > New** so the folder exists),
and then the scene.
## You made a game
What you used:
- **Import** and **UUIDs** to bring art in;
- **Pixel Art** for your own textures;
- **primitives, CSG, materials** for the world;
- **visual scripts** with a distance check, a branch, and position changes;
- a **UI canvas** for the HUD;
- **Play mode** to test.
## Where to go next
- Add more villagers and more gates. Each needs its own copy of a script with its own
coordinates.
- Build a moving platform with `SetVelocity` and a `KeyDown` check; see
[Visual scripting](/logic/visual-scripting/#reacting-to-keys-a-four-direction-mover).
- Paint a top-down overworld map with [Tilemaps](/2d/tilemaps/) for a future 2D version.
- Hand the whole thing to an AI: [an agent builds this RPG for you](/ai/ai-builds-the-rpg/).
---
# Publishing on Trisgine Play
URL: https://wiki.trisgine.com/publish/overview/
How a game made in Trisgine gets from the editor to the store at play.trisgine.com, and the steps on the way.
[play.trisgine.com](https://play.trisgine.com) is **Trisgine Play**, the store where games
built on Trisgine are listed, played in the browser and added to players' libraries. The same
site has a **Developer section** where you set up your team and your games.
> [!NOTE]
> Parts of this section are rolling out to play.trisgine.com: **groups**, **Open in editor** and
> **Publish** from the editor. If you don't see them yet, they arrive with the site's next update.
The road from an idea to a listed game:
1. **A Trisgram account.** The same account signs you in to the store and to the editor.
On [play.trisgine.com](https://play.trisgine.com), click the person icon, **Sign in**, then
**Create one**: a username (no `@`), your email and a password. You're signed in straight
away; confirm your email with the 6-digit code it sends.
2. **A company or a group.** Every game belongs to one. A *group* is the quick way: a name
and you're done. A *company* is a registered business and can sell games.
3. **A game.** It starts as a private **draft** that only your team can see.
4. **A build.** The playable files: published straight from the editor, or uploaded as a ZIP.
5. **A store page.** Title, description, cover, banners, screenshots, trailer, page theme.
6. **Review.** A Trisgram admin plays the build and approves it.
7. **Published.** The game appears in the store and players can add it to their library.
```text
Details ─▶ Build ─▶ Store page ─▶ Submit for review ─▶ In review ─▶ Published
```
The game's **Overview** tab shows this same progress bar, with the step you're on highlighted.
## Company or group?
| | Group | Company |
|---|---|---|
| For | a team, a hobby project, a game-jam team | a registered business (s.r.o., OSVČ, …) |
| You enter | a name | a name, the legal name, the IČO; VAT number optional |
| Approval | none to create; **publishing rights** are granted by Trisgram on request | a Trisgram admin reviews the company before it can publish |
| Games | free only | free and paid |
| Public studio page | no: the store names the group under its games, without a link | yes |
| Product keys and access grants | no | yes |
A group can become a company later with **Request company status**.
## In this section
- [Create a company or group](/publish/company-or-group/)
- [Create a game](/publish/create-a-game/)
- [Builds and channels](/publish/builds/)
- [The store page](/publish/store-page/)
- [Review and release](/publish/review-and-release/)
- [Your team](/publish/team/)
---
# Create a company or group
URL: https://wiki.trisgine.com/publish/company-or-group/
Set up the team your games belong to on Trisgine Play, and ask for the right to publish.

## Open the Developer section
Sign in at [play.trisgine.com](https://play.trisgine.com) (the person icon at the top right,
then **Sign in**). Once you're signed in, the top bar shows **Developer section**.
- If you don't belong to a company or group yet, it offers to create one.
- If you belong to several, it asks you to **Choose a company or group**. The one you pick is
where **Developer section** takes you next time. **Switch company or group** (top right of
every developer page) brings the list back.
## Create a group
1. Choose **Group** under *What are you creating?*
2. Type a **Group name**.
3. Click **Create group**.
You land on the group's **Overview**. You are its **Group admin**.
A new group can already create games, build them and edit their store pages, but it can't
publish them yet. Click **Request publishing rights** on the Overview: the page then reads
*"Requested on (date). A Trisgram admin will decide."* You can keep working on your game in
the meantime.
## Register a company
1. Choose **Company**.
2. Fill in **Company name**, **Legal name**, and **IČO (company ID)**, the eight-digit Czech
company identification number from the Business Register. **VAT number** is optional.
3. Click **Register**.
Until a Trisgram admin approves it, the company is visible only to you and can't publish
games. Once it is approved, it gets a public **studio page** in the store, and can sell games,
set prices, generate product keys and grant access.
> [!TIP]
> Not sure? Start with a group. It takes ten seconds, and you can turn it into a company later
> with **Request company status** on its Overview.
## Company profile
A company admin fills in the public studio page under **Settings**: **Display name**,
**Tagline**, **Description**, **Accent colour**, **Public address**, plus a **Banner** and an
**Avatar** image (PNG, JPEG, GIF or WebP). One account can create up to 5 companies and groups
in total.
## The Overview page
| Section | What it shows |
|---|---|
| **Publishing games** | whether this team may publish, and the request button if not |
| **Games** | how many games are in *Draft*, *In review*, *Published* and *Withdrawn*, plus **New game** |
| **Builds waiting for live** | web builds newer than what each game's live channel serves |
Next: [create a game →](/publish/create-a-game/)
---
# Create a game
URL: https://wiki.trisgine.com/publish/create-a-game/
Create a game draft on Trisgine Play, choose its address, and open it in the editor.
## Create the draft
Games are created by an **admin** of the company or group (members can work on them, see
[Your team](/publish/team/)). A group or company that is still waiting for publishing rights can
already create, build and edit games; it just can't submit them yet.
1. In the **Developer section**, open your company or group, then **Games** (or **New game**
on the Overview).
2. Fill in the form:
| Field | Notes |
|---|---|
| **Title** | the name players see |
| **Address** | the game's web address, e.g. `meadow-quest`. Lowercase letters, digits and single hyphens. Type it yourself: it isn't filled in from the title. Once it is valid, the form previews the store-page and play addresses it gives. |
| **Category** | Adventure, Action, Puzzle or Simulation |
| **Tagline** | optional, one line under the title |
| **Description** | the store text |
3. Click **Create game**. A message confirms *"… created as a draft."*

A **draft** is visible only to members of your company or group. The game's page has these
tabs:
| Tab | For |
|---|---|
| **Overview** | progress, **Open in editor**, **Submit for review** |
| **Builds** | upload a build, publish one made in the editor, publish to live or demo |
| **Branches** | the channels (`live`, `demo`, your own) and CI deploy tokens |
| **Store page** | details, start screen, price, planned release, images, trailer, page theme |
| **News** | posts shown with the game |
| **Access** | who may play a paid game, and product keys (companies only) |
| **Statistics** | play statistics |
| **Review** | the listing status and Trisgram's latest note |
## Open it in the editor
**Open in editor** on the Overview opens the Trisgine editor in a new tab, on **this game's
own world**, already signed in as you. Build your game there.
> [!IMPORTANT]
> The editor opens in a new tab. If your browser blocks it, the page says
> *"The browser blocked the editor's tab. Allow pop-ups for this site and try again."* Allow
> pop-ups for play.trisgine.com and click the button again.
Everything in the rest of this wiki, such as [the 3D tutorial](/rpg/overview/) and
[Meadow Quest](/rpg2d/overview/), works the same in a game's editor tab.
Next: [builds and channels →](/publish/builds/)
---
# Builds and channels
URL: https://wiki.trisgine.com/publish/builds/
Get a playable build onto a game, from the editor or as a ZIP, and choose who can play it with channels.
A **build** is the playable game: the files a browser loads. A **channel** (also called a
branch) points at one build. Players reach a game through its channels.
| Channel | Who can play it | How it changes |
|---|---|---|
| **live** | everyone, once the game is published | **Publish to live** on the Builds tab, which goes through [review](/publish/review-and-release/) |
| **demo** | everyone, once published; never with a key | **Publish to demo** / **Unpublish demo** |
| your own (e.g. `preview`) | only people with its key link (private), or everyone (public) | point it at any build, any time |
Moving a channel to another build, or back to an older one, never re-uploads anything. Each
channel keeps the files of its 5 newest builds; a build a channel points at is never removed.
A free game has 3 channels, a paid one 5, `live` and `demo` included.
## From the editor
1. On the game's **Overview** (or **Builds**), click **Open in editor**.
2. Build your game, then click **Publish** in the editor's toolbar. The editor saves a numbered
**version** of the game's world and turns it into a build, step by step:
*every change is on the server → snapshot cut → release created → … → built: build.zip*.
It ends with **vN exported**.
3. Read the warnings it prints. Two common ones: *the scene has no active camera* (the published
game would show a black screen: add a 2D or 3D camera), and a sky whose default textures
don't ship.
4. Click **Continue on games web**. It opens the game's **Builds** tab.
5. Under **Publish from the editor**, find your version (**Show saved versions** lists them) and
click **Publish to…**. Choose **live**, **demo** or **New channel**, add an optional note, and
click **Publish**. The page shows *"vN is on preview as vN-…"* when the upload is done; it
takes a little while for a ~20 MB build.

After a Publish, the editor shows that version **read-only** (a yellow bar: *Viewing vN …
(read-only)*). Click **Back to live** to keep editing.
> [!WARNING]
> Publishing from the web editor is brand new. Today a game's editor tab saves *changes to*
> existing objects (moving, rotating, scaling) to the game's world, but objects you **create
> or delete** there, or a scene you open from a file, stay in your browser and are not part of
> the published version. Saving all of it to the game's world is being finished. Until then,
> check what a published build contains by playing its channel link before you send it for
> review.
## Upload a ZIP
If you have a build from somewhere else (for example a native or exported game):
| Field | Notes |
|---|---|
| **Version** | letters, digits, dot, hyphen or underscore, starting and ending with a letter or digit (e.g. `1.0.2`) |
| **Platform** | web, vr, windows, linux, macos or android |
| **Build archive** | a ZIP of the build folder's **contents**; a web build needs `index.html` at its root |
| **Release notes** | optional |
Click **Upload build**. The limit is 30 MB per build by default.
## Your first build
The **first** build a game gets also becomes its `live` build, so the reviewer has something to
play. Nobody else can play it until the game is approved and published.
## Sharing a private channel
On **Branches**, each channel has a **Play** link. For a private channel the link carries its
access key: anyone you give it to can play that build, even before release. **Replace play key**
makes old links stop working. **Make public** opens the channel to everybody; **Delete** removes
it.
## Uploading from CI
On **Branches**, a private channel can have **deploy tokens**. Create one, store it as a masked
CI/CD variable, and paste the **GitLab CI snippet** the page generates: it zips your build folder
and uploads it to that channel on every pipeline. A token can never reach `live` or `demo`;
those change only when a person publishes.
Next: [the store page →](/publish/store-page/)
---
# The store page
URL: https://wiki.trisgine.com/publish/store-page/
Everything on a game's Store page tab, from the description and price to banners, screenshots, the trailer and the page theme.
The **Store page** tab decides how your game looks in the store. Each block has its own
**Save** button, so save one block before you move on to the next.
## Details
**Title**, **Address**, **Category**, **Tagline** and **Description**, the same fields as when
you [created the game](/publish/create-a-game/). **Access** is *Free* or *Paid*; groups publish
free games only.
## Start screen
**Show the game's start screen**:
- **On**: **Play** opens your game's own start screen, and the player starts it.
- **Off**: **Play** shows a loader, and the game starts by itself once it has loaded. Its sound
stays off until the player's first key press or click (browsers require that).
## Price
Companies set a price in **CZK**, **USD** and **EUR**, then **Save prices**. A group's games are
free, so a group has no price to set.
## Planned release
Shown with *Coming soon* in the store, as exactly as you know it: an **exact date**, a
**month**, a **quarter** or a **year**. Saving it does **not** send the game to review.
## Images
The files are checked by their contents: an image renamed to the wrong extension is refused.
| Image | Where it shows | Recommended | Size limit |
|---|---|---|---|
| **Cover** | the game page; stands in for missing images | | |
| **Store preview** | store cards and every list | 1280 × 800 | about 1 MB |
| **Banner, narrow (4:3)** | key art on phones and narrow windows | 1600 × 1200 | about 8 MB |
| **Banner, standard (21:9)** | key art on ordinary desktop widths | 2560 × 1080 | about 8 MB |
| **Banner, wide (32:9)** | key art on wide and ultrawide monitors | 3840 × 1080 | about 8 MB |
| **Logo** | a transparent PNG drawn over every banner instead of the title | | 1 MB |
| **Screenshots** | the media strip on the game page | | |
Each screen gets the banner shape that crops least. A shape you didn't upload is filled by the
nearest one you did, and with none by the cover. **Logo placement** sets where the logo sits.
**Engine** and **Platforms** are free text shown on the page, as you write them.
## Trailer
A **YouTube** link (`youtube.com/watch?v=…`, `youtu.be/…`, a Shorts or embed link) or the
11-character video id. It is shown first among the page's media. Nothing loads from YouTube
except its picture until a visitor starts the video.
## Page theme
Give the game page its own look; the store's header and navigation keep the store's style.
- **Colours**: background, surface, text, accent and button text, or **Use our own colours**.
- **Fonts**: a heading font and a body font, from a list that includes pixel fonts such as
*Pixelify Sans*, *Press Start 2P* and *VT323*.
- **Corners** (square, rounded, pill), **Buttons** (filled or outline), **Heading case**.
- **Page background**: an image behind the page (PNG, JPEG, GIF or WebP, usually up to 8 MB).
The background colour is laid over it so the text stays readable.
- **Description format**: *Plain text*, or *Markdown*.
A live **Preview** at the bottom shows the result. **Save theme** applies it; **Reset to
default** undoes it.
Next: [review and release →](/publish/review-and-release/)
---
# Review and release
URL: https://wiki.trisgine.com/publish/review-and-release/
Send a game for review, what Trisgram checks, and what you can still change once it is in the store.
## Before you can submit
- **Publishing rights.** A company gets them when Trisgram approves it. A group asks for them
with **Request publishing rights** on its Overview. Until then, the game page says *"You can
build and edit this game, but you cannot submit or publish it until Trisgram grants … game
publishing."*
- **A web build**, because the reviewer plays the game. Or tick **Coming soon (no build yet)** to
send it without one: once approved it is listed as *Coming soon*, with nothing to play, until a
build is published to live. A [planned release](/publish/store-page/#planned-release) date
shows with it.
- **A store page** that is ready to be seen.
## Submit
On the game's **Overview**, click **Submit for review**. The status moves from **Draft** to
**In review**.
A Trisgram admin plays the build and decides:
- **Approved**: the game is **Published** and appears in the store.
- **Changes requested**: it returns to **Draft** with a note. Read it on the **Review** tab, fix,
and submit again.
While a game is in review, **Publish to live** publishes nothing.
## After release
| You can still | Notes |
|---|---|
| publish new builds to live | through **Publish to live** on the Builds tab |
| change Free / Paid, start screen, prices, planned release | companies only for paid |
| post **News** | shown with the game |
| **Withdraw from the store** | hides it; **Relist** brings it back |
The game's **address** is frozen once it has been published. Its title, description and other
details can then be changed only by Trisgram, so ask if you need an edit.
## What players see
A published game has a page in the store with **Play** and **Add to library** (and **Play demo**
when there is one), player reviews with 1–5 stars, release notes, and a **Follow** button.
Players who aren't signed in can play too: **Play** opens the game in a new tab.
Next: [your team →](/publish/team/)
---
# Your team
URL: https://wiki.trisgine.com/publish/team/
Invite people to your company or group, answer join requests, and choose who is an admin.

Open your company or group in the **Developer section**, then **Members**.
## Roles
| Role | Can |
|---|---|
| **Member** | see the team, its games and their private channel links, and **Open in editor** to work on a game |
| **Admin** (*Group admin* / *Company admin*) | create, edit and publish games, upload builds, edit store pages and company settings, invite people, answer join requests, change roles |
An admin changes someone's role with the drop-down next to their name.
> [!NOTE]
> A team always needs an admin: you can't demote the last one. Make somebody else an admin
> first; without one, nobody could invite people, answer join requests or publish.
Members are shown by the display name on their Trisgram account, otherwise by their username.
Removing someone from a team is done by Trisgram; ask if you need it.
## Invite someone
1. Click **Create invite link**.
2. Copy the link and send it to the person. It lets **one** person join, as a member, works
**once**, and expires after **7 days**.
The person opens the link while signed in and clicks **Join the company**. A link that no longer
works says so: it may have expired, been revoked or been used already. Create a new one.
The link itself is shown only when it is created. If you lose it, revoke it under **Open links**
and create a new one.
## Join requests
Requests to join your team appear under **Join requests**, where an admin accepts or rejects
them.
---
# Working with AI
URL: https://wiki.trisgine.com/ai/overview/
The three ways an AI can help you build in Trisgine, and which one to pick.
The editor has no chat panel built in. Instead, Trisgine is easy for **any** AI to work with,
because everything in it is either **plain text** or reachable through a **JavaScript API**
in the page. There are three ways to use that:
| Approach | What the AI does | Best for | Page |
|---|---|---|---|
| **1. Browser agent** | drives the live editor: creates entities, writes scripts, imports files, presses Play, checks results | "build this for me", testing, repetitive edits | [Browser agents](/ai/browser-agents/), [the tgDebug API](/ai/tgdebug-api/) |
| **2. Text authoring** | writes `.tgscene`, `.tgscript`, `.uidoc`, `.tgtilemap` files that you import | designing levels and logic in a chat window | [Scenes](/ai/authoring-scenes/), [Scripts](/ai/authoring-scripts/) |
| **3. Generative art** | paints sprites and textures from a prompt, inside the Pixel Art editor | art you don't want to draw by hand | [Pixel art generation](/ai/pixel-art-generation/) |
You can mix them: ask a chat AI for a script, paste it into the Script Editor's **Text** tab,
and let an agent attach it to twenty objects.
## Why it works well
- **Scenes are text.** A whole level is a short, indented list of entities and components
([format](/reference/scene-format/)). Models read and write it reliably.
- **Scripts are text too.** A visual script round-trips through a JavaScript-like text form,
so an AI writes the text and you get a real node graph.
- **The editor exposes its own controls.** `window.tgDebug` lets code select, create, load,
save, play, stop and inspect, and it answers in JSON. `window.tgInput` presses keys.
`window.tgImport` imports files. This is the same surface the engine's own automated tests use.
- **Errors are explicit.** Script compilation returns *refusals* with reasons, and import
returns what it accepted and what it refused. An agent can read its mistakes and fix them.
## Give your AI the context
Point the AI at the [prompt library](/ai/prompt-library/). It has ready-made system prompts
that describe the formats and the limits, so the model doesn't invent features. For agents that
can fetch URLs, [`/llms.txt`](/llms.txt) is a compact index of this wiki, and
[`/llms-full.txt`](/llms-full.txt) has every page in one file.
## A complete example
[An agent builds the RPG](/ai/ai-builds-the-rpg/) takes the whole
[Village Gate tutorial](/rpg/overview/) and does it with one script and one prompt.
---
# Browser agents
URL: https://wiki.trisgine.com/ai/browser-agents/
Letting an AI agent drive the live web editor through Chrome, Playwright or the DevTools protocol.
A **browser agent** is an AI that controls a real browser: it reads the page, runs JavaScript
and takes screenshots. Pointed at the Trisgine editor, it can build and test scenes for you.
## What the agent needs
1. A browser with **WebGPU** (Chrome or Edge), with the editor open:
`https://editor.trisgine.com`.
2. The ability to **evaluate JavaScript in that tab**. Almost every agent tool has this:
| Tool | How it runs JS in the page |
|---|---|
| Claude in Chrome / other browser extensions | their "run JavaScript" tool |
| Playwright (or the Playwright MCP server) | `page.evaluate(() => tgDebug.scene())` |
| Puppeteer | `page.evaluate(...)` |
| Chrome DevTools Protocol | `Runtime.evaluate` with `awaitPromise: true` |
| You, by hand | DevTools console (F12) |
3. Screenshots, if you want the agent to *see* the result. Page screenshots work. Reading the
WebGPU canvas from page JavaScript usually gives blank pixels, so let the tool capture the tab.
## Why not just click?
The editor's UI is drawn by the engine onto one `