このページはまだ日本語訳がないため、英語の原文を表示しています。
ガイドTemplates
A new project starts from a template: a small, complete game that builds, runs and passes its tests before you change a line. game new writes one into a new directory, and NSGo's nsgo init -template writes the same files from the template's Go module. For a class or jam, see the Teaching and game jams checklist. When growing a template into a shippable game, follow the Accessibility Guide to wire gameui.SettingsMenu, a11y.Assist, captions, and effects end to end (shipping a ready Accessibility settings screen in every template is tracked in #1783). See Testing games for the test layers used by the templates.
Choose a starting point by genre in the genre guide, which maps each template to the packages and examples a game of that kind uses.
Every generated project includes AGENTS.md with the project rules and CLAUDE.md, which imports it for Claude Code. Read those files before editing. Run go tool game mcp install once to register the editor and running-game MCP servers in the project-level Claude Code and Codex configuration files, then use go tool nsgo dev -automation to expose the bridge while the game runs.
The first-launch gate is the smallest complete accessibility slice. Mount gameui.FirstLaunchSettings.View above the title screen before starting audio, use the same save.DefaultSettingsStore for gameui.SettingsMenu and a11y.NewAssistFromSettings, and route More options to the menu's Accessibility tab. Continue enables captions and records a completion marker, so a later launch can start directly at the title screen. Templates should expose the same entry point from their pause menu and keep the gate's one-action keyboard, gamepad, and touch path.
The templates
| Template | What it is | nsgo init -template module |
|---|---|---|
starter |
A tap-to-score 2D game: an animated sprite on a fixed-step loop, a native HUD and headless tests, the smallest project to grow from. The default. | github.com/nsgo-dev/game/template |
action3d |
A third-person 3D action adventure: an orbit camera, run, jump and attack animations blended by a state machine, melee enemies, and a key that opens the gate to the goal (guide). | github.com/nsgo-dev/game/template/action3d |
cards2d |
Suit Ladders, a single-player drag-and-drop card game with the deck and table in YAML, numbered deals, and localized notices for newer saves and failed writes. | github.com/nsgo-dev/game/template/cards2d |
coop2d |
The authoritative rules of a 2D co-op room for one to four players: room codes and invite links, a fixed tick, rejoining within a grace period, a teammate reviving a downed player and a solo respawn, with tuning in YAML and headless tests; no network transport yet (guide). | github.com/nsgo-dev/game/template/coop2d |
fighting2d |
A one-on-one 2D fighting game: two original fighters with special moves from motion inputs, combos, guards high and low, rounds and a timer, against a CPU opponent or a second player, played with the keyboard, game controllers or touch. The fighting game template describes it. | github.com/nsgo-dev/game/template/fighting2d |
fps3d |
A first-person shooter arena in 3D: hitscan and projectile weapons, enemies that patrol, hunt and shoot with ai and physics3d, health and ammo pickups and three waves to clear, played with the keyboard and mouse, a game controller or touch. The fps3d template describes it. |
github.com/nsgo-dev/game/template/fps3d |
idle |
An idle game: generators, upgrades, large numbers, offline progress on return and prestige, with a win and a loss; The idle template describes it. | github.com/nsgo-dev/game/template/idle |
tap2d |
A one-touch endless game for phones and web: a deterministic difficulty curve, instant retry, a saved best score and a portrait canvas. The tap2d template includes localized notices for save failures. | github.com/nsgo-dev/game/template/tap2d |
platformer2d |
A side-scrolling platformer (guide): a controller with coyote time and jump buffering, three rooms with camera bounds, spikes, pits, sparks to collect, a checkpoint and a goal, played with the keyboard, a controller or touch. | github.com/nsgo-dev/game/template/platformer2d |
puzzle2d |
Spark Slide, a 2D grid puzzle: slide a spark across the board to light every lamp, with levels in YAML, undo and redo, a move limit, stars per level and a level select that saves progress. It plays with the keyboard, a game controller, touch and the mouse and shows localized save notices. | github.com/nsgo-dev/game/template/puzzle2d |
racing3d |
A 3D racer: two laps of a closed circuit against racing-line rivals, with raycast cars, checkpoints, a countdown, a best-lap ghost and a results screen, played with keyboard, gamepad or touch. Racing 3D template | github.com/nsgo-dev/game/template/racing3d |
rhythm |
Pulse Lanes, a four-lane rhythm game: charts in YAML on a beat map, a music clock that keeps the notes in time with the music, Perfect, Great, Good and Miss judgements, combo, score, rank and an energy bar to clear or fail by, audio and video latency calibration kept per device, and best clears saved with localized notices for failures. It plays with the keyboard, a game controller, touch and the mouse (guide). | github.com/nsgo-dev/game/template/rhythm |
roguelike2d |
A turn-based roguelike (guide): five floors generated from the run's seed as BSP rooms and caves, bump-to-attack combat, weighted loot with pity, stats with equipment and timed tonics, a quaff and a cleave on turn cooldowns, permadeath and a run summary, played with the keyboard, a controller or touch. It explains startup save recovery per slot. | github.com/nsgo-dev/game/template/roguelike2d |
rpg2d |
A top-down RPG: a town and a meadow to walk, people with branching dialogue, an inventory with equipment, one quest, turn-based battles and three save slots. Guide. | github.com/nsgo-dev/game/template/rpg2d |
rts2d |
A 2D real-time strategy skirmish: gather crystals, build barracks, train three unit types and destroy a computer opponent's headquarters, with fog of war, box selection, control groups and keyboard, gamepad and touch controls (guide). | github.com/nsgo-dev/game/template/rts2d |
shmup2d |
A vertical scrolling shooter: enemy waves and a stage in YAML, bullet patterns, power-ups, bombs, a boss with three phases, lives and a score, played with the keyboard, the mouse, a controller or touch (guide). | github.com/nsgo-dev/game/template/shmup2d |
towerdefense2d |
A 2D tower defense game: towers with upgrades beside a road enemies follow, waves defined in YAML, money and lives, played with keyboard, gamepad or touch; Tower defense template describes it. | github.com/nsgo-dev/game/template/towerdefense2d |
visualnovel |
A short branching visual novel: two characters, drawn backgrounds, choices that change the ending, a backlog, auto and skip modes, save slots and two languages (guide). | github.com/nsgo-dev/game/template/visualnovel |
go run github.com/nsgo-dev/game/cmd/game@latest new -list prints the same list from the command itself, the default first.
Every template sets launch_screen.background and its dark value in nsgo.yaml to match the first frame, avoiding a light or platform-default flash on iOS and Android 12+. Add a transparent image when your game has a logo.
Create a project from a template
go run github.com/nsgo-dev/game/cmd/game@latest new -list
go run github.com/nsgo-dev/game/cmd/game@latest new -template starter mygame
Inside the created project, run subcommands with go tool game <command> (Command Line).
Without -template, game new uses starter. A name that is not in the list is refused with the names that are. Shell completion for game (Command Line) completes -template with the same names. Command Line describes the other flags.
Copy an existing project
game new -from <directory> <dir> starts a project from a copy of another game project instead of a template: an example such as examples/caverun in a checkout of this repository, a game of your own, or a template pack. The source must hold go.mod, nsgo.yaml and game.yaml; -from and -template cannot be used together. The resulting origin.digest is the SHA-256 digest of the copied, rendered files using the same listing algorithm as game library digest.
The copy gets the new project's module, name and id: go.mod names the module from -module (or the name), every import of the source module's packages is changed to the new module, go.mod loses the replace directives that point at a local directory (an example's replace github.com/nsgo-dev/game => ../..), and the name and id of game.yaml and nsgo.yaml are set as for a template. A file ending in .tmpl is rendered as a template's is.
Files that belong to the source's machine are left out: .git, .nsgo, .DS_Store, .env*, go.work and go.work.sum, node_modules, dist at the root, *.tmp and *.local, and signing material and keys (*.pem, *.key, *.p8, *.p12, *.pfx, *.jks, *.keystore, *.mobileprovision, keystore.properties, id_rsa* and id_ed25519*). A symbolic link or other special file in the source stops the copy before anything is written.
The new game.yaml records the source in origin (Project File): kind is pack for a directory with a pack.yaml, example for a module under github.com/nsgo-dev/game/examples, and directory otherwise, and source is the source's module path. A project made from a template records kind: template with the template's module and name.
NSGo's own command writes a template from its module without the game tool, with an NSGo command that supports Go module templates, such as the installed nsgo of v0.4.0 or later (Command Line):
nsgo init -template github.com/nsgo-dev/game/template -module example.com/mygame mygame
Use the module the table names for each template, and add @<version> to pin one. The project's game.yaml and nsgo.yaml keep the template's own game name and identifier until you edit them, where game new sets them from the directory or -name.
How the templates are laid out
Each template is a Go module of its own in this repository, because nsgo init -template writes the template directory at the root of the module it is given. starter is the template/ module itself; every other template is the module github.com/nsgo-dev/game/template/<name> in template/<name>/:
template/
├─ go.mod module github.com/nsgo-dev/game/template
├─ template/ starter
└─ <name>/
├─ go.mod module github.com/nsgo-dev/game/template/<name>
└─ template/ the <name> template
├─ go.mod.tmpl
├─ go.sum
├─ game.yaml
├─ template.yaml
├─ nsgo.yaml
├─ main.go
├─ …_test.go
├─ README.md
├─ .gitattributes
└─ .gitignore
internal/gamecli/
├─ templates.go the registry: one entry per template
└─ _templates/projects/
├─ starter/ a copy of template/template
└─ <name>/ a copy of template/<name>/template
game new embeds the copies under _templates/projects, so it works from the module cache without this repository. The repository's go.work uses every template module, so from a checkout go tool nsgo dev ./template/<name>/template runs a template and go tool nsgo test ./template/<name>/template tests it against the local game layer.
Add a template
A template is added in one pull request of its own:
- Create the module:
template/<name>/go.moddeclaringmodule github.com/nsgo-dev/game/template/<name>with thegoline oftemplate/go.mod, and the project intemplate/<name>/template/. Its name is lower-case letters, digits and-, starting with a letter, and nottemplate. - Add
./template/<name>to theuselist ofgo.work. - Copy the project into the
gameCLI package, frominternal/gamecli:cp -R ../../template/<name>/template _templates/projects/<name>. - Write the template's
template.yaml, withid: <name>and asummary.enof one line saying what the game is, and add one entry toprojectTemplatesininternal/gamecli/templates.go:newProjectTemplate("<name>", templateModuleRoot+"/<name>"). - Add a row for the template to the table above, in
docs/en/templates.mdanddocs/zh/templates.md, and a fragment underchangelog.d/.
The project in template/<name>/template/ follows these rules, which the tests check where they can:
go.mod.tmplstarts withmodule {{.Module}}, requires a published version ofgithub.com/nsgo-dev/gamethat has every package the template uses, and hastool github.com/nsgo-dev/nsgo/cmd/nsgo. It is the only file with a template action:game newandnsgo initrendernsgo.yaml,main.goand any other.tmplfile too, but CI renders onlygo.mod.tmpland the template must also build as it is in the workspace, so each of those must render to itself, andmain.gocannot hold{{, as a composite literal such as[]T{{...}}does; put such code in another Go file. Other files are copied as they are and may hold any bytes. A file namedgo.modwould make the directory a module of its own, which neithergo:embednor the workspace can include.go.sumholds the sums of the pinned modules. Write it by turninggo.mod.tmplinto ago.modin a copy of the template outside the repository and runningGOWORK=off go mod tidythere.game.yamlis canonical, asgo run github.com/nsgo-dev/game/cmd/game project checkreports, and declares export presets for all six primary platforms (macos_arm64,windows_x64,linux_x64andlinux_arm64,iosfor devices—leavingios_simulatorfordev—android_arm64, andweb).nsgo.yamlagrees with it and keepsbuild.targetsto the cross-host targets every OS can build (windows_x64,linux_x64,linux_arm64,android_arm64,web) so plaingo tool nsgo buildsucceeds on Linux and Windows whilego tool game releasebuilds every preset the host supports;game newreplaces thenameandidof both.main.go,README.md,.gitattributes,.gitignoreand tests are there, andgo run ./cmd/game index templatefrom the repository root has nothing left to do..gitattributessets* text=auto eol=lfso text files stay on LF across operating systems (even when Git for Windows defaults tocore.autocrlf=true), marks binary media extensions asbinaryafter it, and wires*.scene.yaml/*.scene.ymltomerge=nsgo-scene;.gitignoreignores.nsgo/,.game/anddist/.- Every file the template's author writes is text, as for any project in this repository.
The tests of internal/gamecli fail when any of these steps is missing: when the copy under _templates/projects differs from the module's template directory by a byte, when a template/*/template directory has no registry entry, when a registry entry has no copy, module or go.work entry, when any template's .gitattributes or .gitignore is missing the required rules, and when this page or its Chinese counterpart has no row naming a template and its module. They also create a project from every template, build it against the local game layer and run its tests.
CI's templates job needs no edit for a new template: it lists template/template and every template/*/template directory and tests each template the way a developer's project gets it: it copies the template out of the workspace, renders go.mod for example.com/<name>game, and runs go tool nsgo test ./... with GOWORK=off, so the project builds against the game layer version go.mod.tmpl pins rather than this checkout. A Windows CI job (templates-windows) also clones a template with core.autocrlf=true and runs its tests to verify the .gitattributes LF rules keep canonical YAML tests green. A template that needs a package not yet published bumps that pin once the package is on main.
Template manifests
Every template ships a template.yaml beside game.yaml, which describes it to the tools that offer it: game new -list prints its summary, game new -list -json prints the whole manifest, the editor Start Screen takes the card's title, summary and dimension from it, and the editor MCP tool templates_list returns it filtered by genre, dimension, orientation, input and player count. The format is read and written by pkg/tooling/templatemeta (Parse, Validate, Encode), and its JSON Schema is published at https://nsgo.games/schemas/template.v1.json.
| Field | Meaning |
|---|---|
version |
1 |
id |
the template's name, as game new -template takes it |
title, summary |
the display title and the one-line description, keyed by locale code; en is required |
genre |
one of action, arcade, card, co-op, fighting, fps, idle, platformer, puzzle, racing, rhythm, roguelike, rpg, rts, shmup, starter, tower-defense, visual-novel |
dimension |
2d or 3d |
orientation |
landscape, portrait or any |
players |
min and max (at least 1, max not below min), and local and online |
inputs |
any of keyboard, gamepad, touch and mouse |
platforms, tags |
free-form lists, such as [desktop, web, mobile] |
controls |
a description of the controls, keyed by locale code |
cover, playtest |
optional: the gallery cover image and the playtest bot profile |
A manifest is refused, with the field and its line, when it has a field the format does not define, a value outside these vocabularies, or no en title or summary. Encode writes the fields in the order above with map keys sorted, and the tests of internal/gamecli fail when a template's template.yaml is not what Encode writes for it or its id is not the template's name. A template whose manifest does not load or whose id mismatches its registry name is left out of game new -list and the Start Screen and reported, rather than hiding the other templates.
Template gallery media
When game.yaml records origin.kind: template, game check gives advisory residue warnings for byte-equal rule and data files, the project name and window title, and byte-equal README.md and CREDITS.md. origin.keep can suppress rules, data, name, readme or credits deliberately. The origin resolves by path, or by module source when path is omitted. When both fields are present and source names a bundled template, path must name that same template. Other origin kinds, unknown templates and conflicting template identifiers produce no residue warning.
A template card can show a cover image. On the editor Start Screen, editor.ProjectTemplate.Cover is the URI of the image drawn over the card's color swatch; a template without one keeps the swatch. On the website showcase, a ShowcaseEntry in website/src/content/showcase.ts takes an optional cover image and an optional preview clip: the cover loads lazily, and the clip, muted and declared with preload="none", is fetched and played only while the pointer is over the card or focus is inside it, and paused when they leave. No template ships a cover or a clip yet; capturing them from each template's deterministic run is tracked in #1962.
Template briefs
Every template ships a canonical brief.yaml (the game brief, project.Brief) with its pitch, genre, platforms, art direction, tone and audio, and, for the templates whose playtest.yaml takes goals from the brief, those goals as feel targets with the same bounds. Each statement carries a basis: locked is a decision only the person changes, target is an experience goal to aim for, and assumption is a default an agent may revise. The templates mark their briefs assumption and their feel targets, including targets referenced by playtest.yaml, target. The tests of internal/gamecli fail when a template's brief.yaml is missing, not canonical, or uses the wrong provenance, or when a playtest.yaml goal with source: brief.yaml names no target of the brief for its scene, uses the wrong provenance, or differs from it. playtest.RunTest lists every brief target in playtest.report.yaml, keeping a target that was not measured pending (Playtests).
Guarding a run on desktop
If closing the window ends a live match or discards manual progress, have the game report whether it has work to lose and use gameui.GuardQuit to handle the close request, and display gameui.QuitConfirmation. For a match without saves, describe the match the player is about to leave and omit the dialog's Save callback. Autosaving games can allow the adapter to save first. The adapter also handles a forced system quit. Protecting unsaved progress.
Hollowbrook (RPG) asks before discarding progress changed since the last save. Save and quit and background checkpoints both use the Autosave slot under Load game, separately from the manual slots. The RTS skirmish and FPS arena suspend an unfinished match while the player answers the quit dialog and let a finished match close immediately.