Gas2D 0.3.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Gas2D --version 0.3.2
                    
NuGet\Install-Package Gas2D -Version 0.3.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gas2D" Version="0.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Gas2D" Version="0.3.2" />
                    
Directory.Packages.props
<PackageReference Include="Gas2D" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Gas2D --version 0.3.2
                    
#r "nuget: Gas2D, 0.3.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Gas2D@0.3.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Gas2D&version=0.3.2
                    
Install as a Cake Addin
#tool nuget:?package=Gas2D&version=0.3.2
                    
Install as a Cake Tool

gas2d

Gas2D 0.3.2 is a small 2D game layer on top of yak2d. You write a tree of screens that decides what runs, what draws and who gets input; put scenes of entities with components in them when you need a world; and hand the root screen to a Director, which runs everything on yak2d's window.

demo

The parts

  • Director: yak2d's application. It walks the screen tree once per update and once per frame, owns the resources shared by every screen (Director.Shared), and shuts everything down in order (Director.Shutdown).
  • Screens: a tree of Screens with fades, Replace and loading screens, inherited time (Paused, TimeScale, OwnClock) and Covers.
  • Scenes, entities and components: a screen's Scenes, each running entities and their components on a fixed tick (Tick), drawn smoothly between ticks.
  • Rendering: DrawStages filled by a Painter, and a Chain of steps per screen (draw, effects, groups, panes, children); producer chains render into RenderTargets.
  • Physics: Box2D (Box2D.NET) behind gas2d's PhysicsWorld, with Physics and PhysicsBody for scenes.
  • Swarms: Swarm<T>, many small things as plain structs.
  • Input: named actions (InputActions) routed through the screen tree, with InputBelow filters and pointer mapping.
  • Assets: an asset store with a LoadSet per screen, background loading and hot reload.
  • Sound: AudioBus trees with ducking, music hand-over and positioned sound (SoundEmitter).
  • Additions: tweens, a camera rig, state machines, prefabs and pooling, save and load, a debug overlay and replay.

A first game

One screen that owns a camera and a draw stage, fills the stage each frame, and closes when the "quit" action is pressed. The same code is in chapter 1 of the guide.

using System.Numerics;
using Gas2D;
using Colour = Yak2D.Colour;
using CoordinateSpace = Yak2D.CoordinateSpace;
using KeyCode = Yak2D.KeyCode;
using Launcher = Yak2D.Launcher;
using TextJustify = Yak2D.TextJustify;

InputActions actions = new InputActions();
actions.Define("quit", Binding.Key(KeyCode.Escape));

Director director = new Director(new HelloScreen(), new GameSettings { Title = "hello" })
{
    Actions = actions
};

Launcher.Run(director);

public sealed class HelloScreen : Screen
{
    // Screen space: (0, 0) is the middle of the window and nothing moves with a camera
    private static readonly Layer Front = new Layer(0, CoordinateSpace.Screen);

    private readonly DrawStage stage;
    private float angle;

    public HelloScreen()
    {
        Camera camera = Own(new Camera(960, 540));
        stage = Own(new DrawStage(camera) { Name = "hello" });
    }

    protected override void OnUpdate(float seconds)
    {
        angle += seconds;

        if (Input.Pressed("quit"))
        {
            // Closing the root screen ends the game
            Close();
        }
    }

    protected override void OnDraw(Painter paint)
    {
        paint.Text(stage, Front, "hello, gas2d", new Vector2(0f, 60f), 48f, Colour.White, TextJustify.Centre);
        paint.Rect(stage, Front, Vector2.Zero, new Vector2(80f, 80f), Colour.Orange, rotation: angle);
    }
}

The repository

  • src/Gas2d: the library (namespace Gas2D)
  • src/Gas2d.Demo: a small game using every part (dotnet run --project src/Gas2d.Demo)
  • src/Gas2d.Tests: unit tests (dotnet test in src/)
  • docs/guide/: the user guide, starting at docs/guide/index.md, with migrating from 0.2.1
  • docs/screen-tree-design.md: how it fits together and why
  • docs/how-gas2d-works.txt: the same, in plain text

Using the Gas2D package

Gas2D is published on nuget.org (0.3.2 at the time of writing):

dotnet add package Gas2D

Publishing

  1. Bump <Version> in src/Gas2d/Gas2d.csproj: patch for fixes, minor for new API, major for breaking changes.
  2. Push to main. CI (.github/workflows/publish.yml) tests, packs, pushes the package to nuget.org and waits until the new version is live.

A version is never re-published: if <Version> is already on nuget.org, CI skips the push. The nuget.org API key is the NUGET_API_KEY repository secret; nuget.org keys must expire in 30 days or less, so renew it before it lapses (an expired key fails the publish job).

Local feed (optional)

To try unreleased changes in an isolated build (no sibling source, no network), pack to a local folder feed. Use a pre-release version such as 0.3.2-local.1, so it never clashes with a published one.

  1. One-off: register the feed, e.g. dotnet nuget add source ~/nuget-local -n local.
  2. Set <Version> to the pre-release version and pack: dotnet pack src/Gas2d/Gas2d.csproj -c Release -o ~/nuget-local. Never re-pack a version that was already packed: NuGet caches packages by version and would keep serving the old one.
  3. Update the Gas2D package version in the consuming repo and restore it once, so the package lands in your NuGet cache (~/.nuget/packages), which is where offline builds find it.

What changed in 0.3.2

0.3.2 is a fix release and stays compatible with 0.3.1: no API is removed.

  • Screens: AddChild, Replace and RemoveChild throw ArgumentException for duplicate, Dead or queued screens; the TimeScale, SlowScale, DuckLevel, DuckSeconds, EnterSeconds and ExitSeconds setters throw ArgumentOutOfRangeException on NaN, infinity or negative values, and GameSettings checks Width, Height and UploadBudgetMs; screen scenes default to GameSettings.TickSeconds and SubSteps; a never-started root gets no OnClosed and its queued screens are marked Dead; a dropped Replace leaves its next Dead; an Into child's Covers no longer covers its siblings, and root Into is refused.
  • Rendering: needs Yak2D 1.3.2 or later ([1.3.2,1.4)); a pane holding a group, pane, children or image step renders through its own image; Chain.Drawing on a screen's Chain or a group or pane sub-chain throws InvalidOperationException; Draw, Image and Raw throw ArgumentNullException for null; a bad freeze readback is retried; a camera rig can be removed from its own tween.
  • Scenes: Scene.Add throws InvalidOperationException for an alive entity already in a scene (joined, asleep or pooled); re-adding a destroyed entity joins after its old scene's safe point; Scene.Destroy and Scene.Advance throw during that scene's own tick; a component added to a sleeping entity gets OnSleep right after OnAdded.
  • World and physics: ChunkStreamer calls Sleep and Evict before dropping a chunk, so a throw is retried; EditsFor no longer throws for a chunk not woken this session; crossers and SpawnPersistent into a chunk that isn't live leave the live set; stored logs forget WhenStored and future AfterTicks edits; physics throws on bad HitSpeed, same-body joints, bad chains and an inverted SetDistanceRange, and CreateBody leaves no body when a shape fails. New: StoredChunkStreamer.Load(key), GameClock(long ticks) (negative throws) and a SceneThingHost constructor overload taking an isLive func.
  • Assets, audio and input: each LoadSet has its own handle per key, so releasing one set leaves the other's handle alive; Drain does one batched reload and retries an IOException (including FileNotFoundException) at read once; a bus's Pitch multiplies down the chain and TimeFactor is applied once; raw key and mouse questions answer false (MousePosition its default) with no raw input, while Raw itself still throws.
  • Net, replay and save: replays are format version 3, versions 2 and 3 are read and version 1 is refused; bindings changes are recorded mid-stream; lockstep drops far-future input frames and bad checksums; a replay with no end record reads as Truncated; corrupt strings throw only InvalidDataException; Restore sets TickCount and Seed before spawning, and a throwing Load puts them back. New: Rng.Export() and Rng.Import(state, inc), where an even inc throws.

What changed in 0.3.1

0.3.1 is a fix release and stays compatible with 0.3.0: no API is removed.

  • Screens: flush, leak and render fixes.
  • Scenes: timer, origin-shift and chunk fixes.
  • Assets and input: hot-reload and input-cursor fixes.
  • Lockstep, replay and save fixes, with two new public members: ReplayPlayer.Truncated and ReplayHeader.Matches(Scene).
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Gas2D:

Package Downloads
Gas2D.ImGui

Dear ImGui (Hexa.NET.ImGui) for Gas2D: a Yak2D custom Veldrid stage that renders ImGui draw data.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0-preview.1 62 12/4/2026
0.3.2 108 11/30/2026
0.3.1 123 11/16/2026
0.3.0 120 11/16/2026
0.2.1 130 11/15/2026