onix

package module
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Onix

简体中文 · Release platforms · Quick start · Examples · Docs · ☆ Star on GitHub

Onix is a Go engine for 2D and 3D games and interactive applications. Write gameplay in Go, build menus and HUDs with HTML/CSS, and use the project editor or CLI to package the same project for desktop, mobile, the web and WeChat Mini Games.

Engine features

  • Typed gameplay code. Define components as Go types and query entities by the data a system needs. Change filters let systems skip unchanged components, and typed messages connect gameplay modules. ECS API · Module guide
  • Native HTML/CSS UI. Onix lays out and paints the interface alongside the scene. Update text and attributes from Go through DOM handles, and use CSS keyframes and transitions to animate controls. HTML layout and updates · CSS animations
  • 2D and 3D scenes. Animate sprites and Spine skeletons in 2D, or light glTF models with physically based materials and HDR environments in 3D. Both have physics systems for collision and rigid-body simulation. Lighting and materials · 2D physics · 3D physics
  • On-demand rendering. Use continuous rendering for a moving scene, or let a static screen rest until input, a tracked change or an animation requests a frame. Frame scheduling
  • Platform-specific builds. The build pipeline compiles the selected graphics backend and prepares its shaders and textures. Release platforms · Resource packages

Release platforms

Choose a target in Build Project or pass its ID to the CLI with -platform. Each build uses one renderer. The default for each target appears in bold.

Target Build output Renderers Build and release notes
Windows (windows) Portable ZIP or MSI installer DirectX 11, Vulkan, OpenGL Build with MinGW-w64 on Windows or Linux. MSI packaging also requires WiX or wixl.
macOS (macos) .app bundle or .dmg disk image Metal, Vulkan, OpenGL Build a universal or single-architecture app on macOS, or cross-compile it on Linux with osxcross. Creating a DMG requires macOS.
Linux (linux) .tar.gz containing the executable and resources OpenGL, Vulkan Build on Linux for the host architecture.
Android (android) ARM64 APK Vulkan, OpenGL ES Requires the Android SDK, NDK, CMake and JDK 17+. Sign the release APK with your publishing key.
iOS (ios) ARM64 static library (libonix.a) and Swift host files Metal Build on macOS, add the generated files to an Xcode target, then archive and sign the app in Xcode.
Web (web) Static site with HTML, JavaScript and WebAssembly WebGPU, WebGL 2 Deploy the generated directory to a web server. WebGPU requires HTTPS or localhost.
WeChat Mini Games (wechat) Mini Game project with a WebAssembly runtime WebGL 2 Set your Mini Game AppID and open the generated directory in WeChat DevTools to upload it.

Desktop packaging and cross-compilation · Android toolchain · iOS host integration

Quick start

With Go 1.27+, Git and your platform’s native build dependencies installed, create a project alongside the engine checkout. Build requirements

git clone https://github.com/onix-engine/onix.git
cd onix
go run ./editor/cmd/onix new ../my-game
go run ./editor/cmd/onix check ../my-game
go run ./editor/cmd/onix ../my-game

The last command opens the editor for the new project. Use Play to build and run it, or Build Project to package it. Running go run ./editor/cmd/onix without arguments opens the editor's New/Open workflow.

Examples

Screenshot Example source Engine features in use
Metal helmet reflecting a lit hallway Damaged Helmet glTF materials and reflections under HDR environment lighting. Model by theblueturtle_ and ctxwing, environment by Greg Zaal. Asset licenses
A pelican on a bicycle jumping over a crab The Pelican Post Parallax scrolling with SVG sprites and an HTML/CSS HUD.
An animated rider on a purple raptor Spine gallery Switch between eight skeletons and their animations at runtime.
Numbered tiles on a 2048 board 2048 Go move and undo logic updates an HTML/CSS board through DOM handles.
A pixel-art bird approaching green pipes Flappy Bird Typed messages connect the input, simulation and sprite modules.
A grid of CSS keyframe and transition demos CSS animations Native CSS keyframes, transitions and hover interactions.
An embedded page with a button that calls Go WebView A page in the platform WebView calls a Go handler.
White text on a black window Hello World Open a window and render text from a single Go file.

Prerequisites

  • Go 1.27 or newer and Git.
  • A C/C++ toolchain with CGO enabled for native builds. Linux requires the X11, Xext, Xrender, Xi, Wayland, wayland-cursor and xkbcommon development libraries, plus OpenGL for the default renderer. On macOS, install Xcode Command Line Tools.
  • Packaging and cross-compilation require the target platform’s tools. Desktop builds · Android builds

Command reference

All commands below run from the engine checkout. Options precede the project directory.

Task Command
Create a project go run ./editor/cmd/onix new ../my-game
Validate a project go run ./editor/cmd/onix check ../my-game
Regenerate registration go run ./editor/cmd/onix generate ../my-game
Open a project in the editor go run ./editor/cmd/onix ../my-game
Build a desktop release for the host platform go run ./editor/cmd/onix build -mode release ../my-game
Build a Web release go run ./editor/cmd/onix build -platform web -mode release ../my-game

generate preserves the application's main.go. Builds collect and preprocess resources, then produce platform-specific artifacts under the project's dist/. Release builds use the onix_release tag and binary resource packages.

Documentation

Start at the documentation index for usage, design and performance guides, each with a Simplified Chinese version. Focused API and platform references are listed in the usage guide.

Engine development

Read AGENTS.md before changing the engine. Prefer concise generic implementations, minimize allocations on warm paths, and combine traversals when possible. HTML rendering changes must follow W3C standards and align with Chromium.

Run tests for the packages affected by a change. For example, for ECS work:

go test ./ecs
go test ./ecs -run TestName -count=1

Replace TestName with the relevant test name or pattern. Do not run go test ./...; the repository-wide suite can freeze the machine. Visual acceptance is manual; do not launch the editor for automated screenshot testing.

License

Onix is licensed under the MIT License. You may use, modify, compile, and distribute the engine, including in commercial games and software, subject to the license's notice requirements. Third-party code and assets retain their own licenses; see third-party notices.

Documentation

Index

Constants

View Source
const (
	DefaultTargetFPS        = 30
	DefaultTargetTPS        = 64
	DefaultMaxFrameDelta    = 250 * time.Millisecond
	DefaultMaxRendersPerRun = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Animations2D

type Animations2D struct{}

Animations2D installs the animator update systems for node-bound clips.

type App

type App struct {
	World *ecs.World

	*window.Context
	// contains filtered or unexported fields
}

func NewApp

func NewApp() *App

func (*App) AddInputHandler

func (app *App) AddInputHandler(phase input.Phase, handler func(*input.Dispatch))

AddInputHandler registers a synchronous handler for one input phase. Handlers run in registration order and may call Dispatch.Consume.

func (*App) AddSystem

func (app *App) AddSystem(stage Stage, config ecs.SystemConfig) error

func (*App) AddSystems

func (app *App) AddSystems(stage Stage, configs ...ecs.SystemConfig) error

func (*App) Destroy

func (app *App) Destroy()

Destroy releases browser surfaces before destroying the native window.

func (*App) Frame

func (app *App) Frame() error

func (*App) InstallSystems

func (app *App) InstallSystems[T SystemSet]() error

InstallSystems installs one capability and its explicit dependencies. Calls are idempotent, and unused capability implementations can be removed by the Go linker.

func (*App) LoadModules

func (app *App) LoadModules[P module.ContentProfile](plan *project.ProjectPlan, registry module.Registry, options module.Options) (*module.Scene, error)

LoadModules mounts the entry of the new module format. It does not open a native window, so loading and logic tests work independently of rendering.

func (*App) LoadScene

func (app *App) LoadScene(bundle *project.Bundle) (*project.SceneInstance, error)

func (*App) Modules

func (app *App) Modules() *module.Runtime

func (*App) OpenFile

func (app *App) OpenFile(options window.FileDialogOptions) (string, error)

OpenFile opens a native dialog for one file owned by the engine window.

func (*App) OpenFileDialog

func (app *App) OpenFileDialog(options window.FileDialogOptions) ([]string, error)

OpenFileDialog opens a modal native file dialog owned by the engine window. An empty result means that the user cancelled the dialog.

func (*App) OpenFiles

func (app *App) OpenFiles(options window.FileDialogOptions) ([]string, error)

OpenFiles opens a native multi-file dialog owned by the engine window.

func (*App) OpenFolder

func (app *App) OpenFolder(options window.FileDialogOptions) (string, error)

OpenFolder opens a native dialog for one folder owned by the engine window.

func (*App) OpenModuleWindow

func (app *App) OpenModuleWindow(spec project.ProjectSpec, source fs.FS, decoder window.IconDecoder) error

OpenModuleWindow applies project window metadata. LoadModules stays usable without a native window for simulation, build validation and server hosts.

func (*App) RequestRender

func (app *App) RequestRender()

func (*App) Run

func (app *App) Run() error

func (*App) Schedule

func (app *App) Schedule(stage Stage) *ecs.Schedule

func (*App) SetIdleEnabled

func (app *App) SetIdleEnabled(enabled bool)

SetIdleEnabled allows an on-demand app to suspend its schedules between events. Custom time-driven systems must schedule WakeAt or disable idle.

func (*App) SetInitialWindowSize

func (app *App) SetInitialWindowSize(width, height int)

SetInitialWindowSize overrides the project window size before the native window is created. Project window options are still applied by LoadScene.

func (*App) SetRenderMode

func (app *App) SetRenderMode(mode RenderMode)

func (*App) SetScriptRegistry

func (app *App) SetScriptRegistry(registry project.ScriptRegistry) error

SetScriptRegistry installs generated scene script bindings. The registry is applied to the next scene loaded by the app and to the current scene, if one has already been loaded.

func (*App) SetTargetFPS

func (app *App) SetTargetFPS(fps int)

func (*App) SetTargetTPS

func (app *App) SetTargetTPS(tps int)

func (*App) SetWebViewBackend

func (app *App) SetWebViewBackend(backend scene.WebViewBackend)

SetWebViewBackend installs the platform browser backend used by ECS WebView components. It is useful on Linux and mobile, where the host can provide a WebKitGTK or native Android/iOS implementation.

func (*App) SetWindowAlwaysOnTop

func (app *App) SetWindowAlwaysOnTop(enabled bool)

func (*App) SetWindowDragRegion

func (app *App) SetWindowDragRegion(region func(x, y float64) bool)

func (*App) SetWindowIcon

func (app *App) SetWindowIcon(data []byte) error

func (*App) SetWindowInputRegion

func (app *App) SetWindowInputRegion(rects []window.InputRegionRect)

SetWindowInputRegion limits pointer input to logical viewport rectangles. A nil slice restores the full window; an empty non-nil slice passes all pointer input through.

func (*App) SetWindowOptions

func (app *App) SetWindowOptions(options window.Options)

func (*App) SetWindowSize

func (app *App) SetWindowSize(width, height int)

func (*App) SetWindowTaskbarVisible

func (app *App) SetWindowTaskbarVisible(visible bool)

func (*App) SetWindowTitle

func (app *App) SetWindowTitle(title string)

func (*App) Step

func (app *App) Step() (bool, error)

func (*App) ToggleFullscreen

func (app *App) ToggleFullscreen()

ToggleFullscreen switches the native window between fullscreen and its previous windowed bounds.

func (*App) WakeAt

func (app *App) WakeAt(deadline time.Time)

WakeAt schedules one update at the earliest requested deadline. It can be called from another goroutine; ECS writes must stay on the app's loop thread.

type Application added in v0.1.8

type Application struct {
	BetweenFrames func() error
	// contains filtered or unexported fields
}

Application owns multiple native windows in one desktop application instance. Add and BetweenFrames run on the UI thread, outside individual window frames.

func (*Application) Add added in v0.1.8

func (a *Application) Add(app *App, closed func()) error

func (*Application) Close added in v0.1.8

func (a *Application) Close()

func (*Application) Run added in v0.1.8

func (a *Application) Run() error

type Input2D

type Input2D struct{}

type MarkdownRuntime

type MarkdownRuntime interface {
	InstallMarkdown(*App) error
}

MarkdownRuntime is the optional implementation behind UIMarkdown. Keeping the implementation in a feature package lets projects that do not enable Markdown leave its parser dependencies out of the final binary.

type Particles2D

type Particles2D struct{}

type Physics2D

type Physics2D struct{}

type Physics3D

type Physics3D struct{}

type Render2D

type Render2D struct{}

Render2D adds sprites, sprite layers and UI visuals to RenderText2D.

type Render3D

type Render3D struct{}

type RenderMode

type RenderMode uint8
const (
	RenderAlways RenderMode = iota
	RenderOnDemand
)

type RenderText2D added in v0.1.11

type RenderText2D struct{}

RenderText2D installs transforms, 2D cameras and text drawing.

type Spine2D

type Spine2D struct{}

type SpriteTrails2D

type SpriteTrails2D struct{}

type Stage

type Stage string
const (
	StageStartup               Stage = "startup"
	StageInputPreprocess       Stage = "input_preprocess"
	StageInputGlobal           Stage = "input_global"
	StageInputGUI              Stage = "input_gui"
	StageInputShortcut         Stage = "input_shortcut"
	StageInputUnhandled        Stage = "input_unhandled"
	StagePreUpdate             Stage = "pre_update"
	StageBeforeFixedUpdateLoop Stage = "before_fixed_update_loop"
	StageFixedFirst            Stage = "fixed_first"
	StageModuleEvents          Stage = "module_events"
	StageFixedPreUpdate        Stage = "fixed_pre_update"
	StageFixedUpdate           Stage = "fixed_update"
	StageFixedPostUpdate       Stage = "fixed_post_update"
	StageFixedLast             Stage = "fixed_last"
	StageAfterFixedUpdateLoop  Stage = "after_fixed_update_loop"
	StageUpdate                Stage = "update"
	StagePostUpdate            Stage = "post_update"
	StageRender                Stage = "render"
)

type SystemSet

type SystemSet interface {
	// contains filtered or unexported methods
}

SystemSet is a statically selected engine capability. The unexported method keeps installation logic inside Onix while allowing a generic public API.

type Tilemaps2D

type Tilemaps2D struct{}

type Transforms

type Transforms struct{}

type UIControls

type UIControls struct{}

type UIHTML

type UIHTML struct{}

UIHTML installs the HTML component renderer on top of the UI runtime.

type UIMarkdown

type UIMarkdown[F MarkdownRuntime] struct{}

type UITextInput

type UITextInput struct{}

type UIWidgets

type UIWidgets struct{}

type WebView

type WebView struct{}

WebView installs the optional browser surface runtime. The platform backend is created after the window context exists, so projects can install systems before loading their first scene.

Directories

Path Synopsis
codec
Package codec provides the full built-in audio decoder collection.
Package codec provides the full built-in audio decoder collection.
Package ecs provides typed component storage, queries, structural commands, schedules, resources and messages.
Package ecs provides typed component storage, queries, structural commands, schedules, resources and messages.
cmd/builder command
Command builder preprocesses a project resource package before compiling it.
Command builder preprocesses a project resource package before compiling it.
cmd/onix command
examples
2048 command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
animations command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
damaged_helmet command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
flappybird command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
flappybird/contracts
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
hello_world command
pelican command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
spine command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
spine/contracts
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
webview command
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
webview/contracts
Code generated by Onix; DO NOT EDIT.
Code generated by Onix; DO NOT EDIT.
Package fs provides Onix's persistent virtual filesystem.
Package fs provides Onix's persistent virtual filesystem.
codec/hdr
Package hdr decodes Radiance RGBE panoramas without reducing their dynamic range.
Package hdr decodes Radiance RGBE panoramas without reducing their dynamic range.
codec/ontex
Package ontex reads and writes the ONIXTEX1 container: a block-compressed texture together with the mip chain the build already generated.
Package ontex reads and writes the ONIXTEX1 container: a block-compressed texture together with the mip chain the build already generated.
codec/ultrahdr
Package ultrahdr reconstructs linear HDR from JPEG base images and gain maps.
Package ultrahdr reconstructs linear HDR from JPEG base images and gain maps.
html
css
markup
Package markup builds native Onix documents and serializes HTML fragments.
Package markup builds native Onix documents and serializes HTML fragments.
images
png
Package png implements a PNG image decoder and encoder.
Package png implements a PNG image decoder and encoder.
svg
Package svg decodes and rasterizes SVG documents without external dependencies.
Package svg decodes and rasterizes SVG documents without external dependencies.
webp
Package webp implements a decoder for WEBP images.
Package webp implements a decoder for WEBP images.
webp/config
Package config reads WebP headers without registering a pixel decoder.
Package config reads WebP headers without registering a pixel decoder.
webp/internal/riff
Package riff implements the Resource Interchange File Format, used by media formats such as AVI, WAVE and WEBP.
Package riff implements the Resource Interchange File Format, used by media formats such as AVI, WAVE and WEBP.
webp/internal/vp8
Package vp8 implements a decoder for the VP8 lossy image format.
Package vp8 implements a decoder for the VP8 lossy image format.
webp/internal/vp8l
Package vp8l implements a decoder for the VP8L lossless image format.
Package vp8l implements a decoder for the VP8L lossless image format.
internal
brotli
Package brotli implements the Brotli reader and writer needed by external formats: WOFF2 decoding and the WeChat WASM artifact.
Package brotli implements the Brotli reader and writer needed by external formats: WOFF2 decoding and the WeChat WASM artifact.
ecsgen command
Command ecsgen generates typed query, spawn and patch adapters around shared plans.
Command ecsgen generates typed query, spawn and patch adapters around shared plans.
entitycache
Package entitycache stores large system records densely behind a small entity index.
Package entitycache stores large system records densely behind a small entity index.
glyphdraw
Package glyphdraw copies and composites premultiplied glyph pixels into separate RGBA surfaces.
Package glyphdraw copies and composites premultiplied glyph pixels into separate RGBA surfaces.
reuse
Package reuse provides operations on reusable scratch storage.
Package reuse provides operations on reusable scratch storage.
smallsort
Package smallsort provides compact in-place sorting for small collections.
Package smallsort provides compact in-place sorting for small collections.
sourcejson
Package sourcejson isolates build-time JSON parsing from release runtimes.
Package sourcejson isolates build-time JSON parsing from release runtimes.
texcompress
Package texcompress implements pure-Go block compression for build-time texture preprocessing.
Package texcompress implements pure-Go block compression for build-time texture preprocessing.
texcontainer
Package texcontainer describes the byte layout of the block-compressed texture container a build packs in place of a source image.
Package texcontainer describes the byte layout of the block-compressed texture container a build packs in place of a source image.
typedbin
Package typedbin encodes values using their Go type as the schema.
Package typedbin encodes values using their Go type as the schema.
Package module runs independent minimum systems composed by project scene plans.
Package module runs independent minimum systems composed by project scene plans.
assets
Package assets contains opt-in project resource implementations.
Package assets contains opt-in project resource implementations.
audio
Package projectaudio provides an opt-in audio resource feature for project bundles.
Package projectaudio provides an opt-in audio resource feature for project bundles.
internal/dxbcgen command
Command dxbcgen compiles generated HLSL into builtin DirectX 11 bytecode.
Command dxbcgen compiles generated HLSL into builtin DirectX 11 bytecode.
internal/hlslgen command
Command hlslgen regenerates DirectX builtins from the shared WGSL sources.
Command hlslgen regenerates DirectX builtins from the shared WGSL sources.
Package scene provides scene components and runtime systems built on ecs, including transforms, common cameras, 2D rendering, animation, and input.
Package scene provides scene components and runtime systems built on ecs, including transforms, common cameras, 2D rendering, animation, and input.
render3d
Package render3d owns meshes, camera settings, lights, deformation, shadows, post-processing, and the 3D extract/prepare/sort/draw pipeline.
Package render3d owns meshes, camera settings, lights, deformation, shadows, post-processing, and the 3D extract/prepare/sort/draw pipeline.
Package spine loads Spine 3.7 JSON and atlas exports and evaluates them into indexed 2D geometry for Onix's render pipeline.
Package spine loads Spine 3.7 JSON and atlas exports and evaluates them into indexed 2D geometry for Onix's render pipeline.
Package syntax incrementally tokenizes TextMate grammars and colors their scopes with VS Code themes.
Package syntax incrementally tokenizes TextMate grammars and colors their scopes with VS Code themes.
tests
htmlcompat command
Command htmlcompat renders the browser compatibility fixture through Onix.
Command htmlcompat renders the browser compatibility fixture through Onix.
piecetree
Package piecetree stores UTF-8 text in an AVL tree of references into an immutable original buffer and an append-only edit buffer.
Package piecetree stores UTF-8 text in an AVL tree of references into an immutable original buffer and an append-only edit buffer.
tools
ui
Package ui provides layouts, constraints, reusable controls and composition.
Package ui provides layouts, constraints, reusable controls and composition.
html
Package html provides retained HTML surfaces and typed components on the scene runtime.
Package html provides retained HTML surfaces and typed components on the scene runtime.
codec/png
Package png provides the opt-in PNG window icon decoder.
Package png provides the opt-in PNG window icon decoder.
codec/svg
Package svg provides SVG window icon decoding at a statically selected size.
Package svg provides SVG window icon decoding at a statically selected size.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL