NSGo Game
Fixed update step
not running
Measured frames per second
not running
Sprites
not running
Dots you lit
not running
Early: APIs will change

Games in Go,on every NSGo target.

A game layer for NSGo apps: a fixed-step loop, sprites and sound drawn into one native view, with the HUD and menus as ordinary NSGo views on top. It uses only NSGo’s public API, so an app that does not import it links none of it.

go get github.com/nsgo-dev/game/packages/game
Roadmap

Two stages

2D first, then 3D on the same loop, input, sound and scenes.

  • Stage 1 · 2D

    2D

    A fixed-step loop, input actions, sprites, tilemaps, scenes and sound, drawn into a Canvas, a pixel buffer or a shader.

  • Stage 2 · 3D

    3D

    Meshes, cameras, lights and glTF models on a GPU view NSGo adds for it. The loop, input, sound and scenes carry over. (nsgo#1059)

  • Targets · 6

    Where NSGo runs

    • macOS
    • iOS
    • Windows
    • Linux
    • Android
    • Web
Roadmap
Packages

Three packages so far

Each is its own import, tested, and described in the reference. The next ones are planned in issues.

  1. Level 01Cleared

    Loop

    Fixed-step updates on the display’s frames, one interpolated draw per frame. Pauses in the background.

    github.com/nsgo-dev/game/packages/game
  2. Level 02Cleared

    sprite

    Atlases from TexturePacker or Aseprite, frame animations, and Z-ordered batches drawn into a Canvas.

    github.com/nsgo-dev/game/packages/game/sprite
  3. Level 03Cleared

    sound

    A mixer with saved master and group volumes, per-sound limits, and music that crossfades.

    github.com/nsgo-dev/game/packages/game/sound
  4. Level 04Locked

    input

    Named actions bound to keys, gamepads, touch regions and the mouse.

    0 of 13 issues closed
    Plan #3
  5. Level 05Locked

    tilemap

    A camera, and tilemaps from Tiled drawn only where the camera sees.

    0 of 13 issues closed
    Plan #5
  6. Level 06Locked

    scene

    Drawing layers, hit testing for touch and mouse, and switching between scenes.

    0 of 7 issues closed
    Plan #6
import (
	"time"

	"github.com/nsgo-dev/game/packages/game"
	"github.com/nsgo-dev/nsgo/core"
)

func Ball(cx *core.Scope) core.Node {
	var x, last float32
	alpha := core.NewSignal(cx, 0.0)
	loop := &game.Loop{
		Rate: 60,
		Update: func(dt time.Duration) {
			last = x
			x += 120 * float32(dt.Seconds())
		},
		Draw: func(a float64) { alpha.Set(a) },
	}
	loop.Run(cx)
	return core.Canvas{Draw: func(d *core.Drawing, _ core.Size) {
		at := last + (x-last)*float32(alpha.Get())
		d.SetFillColor(core.RGB(0xff5a1f)).FillRect(at, 40, 16, 16)
	}}
}

Make a game with NSGo

Read how a frame runs, then follow the plan on GitHub.