- Fixed update step
- not running
- Measured frames per second
- not running
- Sprites
- not running
- Dots you lit
- not running
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/gameTwo 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
Three packages so far
Each is its own import, tested, and described in the reference. The next ones are planned in issues.
- 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 - 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 - 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 - Level 04Locked
input
Named actions bound to keys, gamepads, touch regions and the mouse.
0 of 13 issues closedPlan #3 - Level 05Locked
tilemap
A camera, and tilemaps from Tiled drawn only where the camera sees.
0 of 13 issues closedPlan #5 - Level 06Locked
scene
Drawing layers, hit testing for touch and mouse, and switching between scenes.
0 of 7 issues closedPlan #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)
}}
}import "github.com/nsgo-dev/game/packages/game/sprite"
//go:embed hero.json
var heroJSON []byte
atlas, err := sprite.LoadAtlas(core.Src("asset:hero.png"), heroJSON)
if err != nil {
return err
}
walk := atlas.Animations["walk"]
hero := sprite.NewSprite(walk.Frame())
hero.X, hero.Y = 120, 80
batch := &sprite.Batch{Atlas: atlas, Sprites: []*sprite.Sprite{&hero}}
// In Loop.Update:
walk.Update(dt)
hero.Frame = walk.Frame()
// In the Canvas's Draw:
batch.Draw(d)import (
"github.com/nsgo-dev/game/packages/game/sound"
"github.com/nsgo-dev/nsgo/audio"
)
mixer := sound.NewMixer(cx, "sound")
mixer.SetVolume("music", 0.6)
music := mixer.Music("music")
music.Play(audio.Source{URI: "asset:theme.m4a"}, 2*time.Second)
jump := audio.Source{URI: "asset:jump.wav"}
audio.LoadSound(cx, jump, func(s *audio.Sound, err error) {
if err != nil {
return
}
effect := mixer.Effect(s, "effects", 4)
effect.Play(audio.Voice{Volume: 0.8})
})Make a game with NSGo
Read how a frame runs, then follow the plan on GitHub.