ASGL2 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ASGL2 --version 3.0.0
                    
NuGet\Install-Package ASGL2 -Version 3.0.0
                    
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="ASGL2" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ASGL2" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ASGL2" />
                    
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 ASGL2 --version 3.0.0
                    
#r "nuget: ASGL2, 3.0.0"
                    
#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 ASGL2@3.0.0
                    
#: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=ASGL2&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ASGL2&version=3.0.0
                    
Install as a Cake Tool

ASGL2

A small 2D game library for .NET 10, built on SDL2. Runs on Windows and Linux from the same code and the same assets, and is documented so that both people and AI coding assistants can pick it up quickly (see "Documentation in this package" below).

  • Game loop and states: GameBase (fixed 60 Hz logic loop, separate render loop), BaseState screens.
  • Graphics: Renderer (any window size, fullscreen), sprites and sprite sheets, scrolling and parallax layers, star fields, Camera (dead zone, look-ahead, shake), TrueType text (TtfFont: UTF-8, rendered sharp at any window scale).
  • Tile maps: layers, collision (MoveAndCollide), animated tiles, and a JSON map format (TileMapData, *.tilemap.json) that the ASGL map editor reads and writes.
  • Gameplay helpers: waypoints, oscillators, phase machines, timers, hitbox and convex polygon collision, particle and floating-text effects.
  • Input and audio: keyboard, mouse and gamepads with per-tick pressed/released edges, text input; sound effects with overlapping sound pools and per-play volume, streamed background music (MusicPlayer, with fades) and pitch-bendable loops, through SDL2_mixer (WAV, OGG, MP3, FLAC).
  • Embedded assets: sprites, sheets, tile maps, sounds, music and fonts can be loaded from resources compiled into the game's executable as well as from files.
  • UI toolkit (ASGL2.UI): panels, buttons, text boxes, list boxes, dialogs (including modal ones that wait for an answer), toolbar and status bar, drawn with SDL.
  • 3D (ASGL2.Graphics3D): a software renderer on top of the 2D renderer, with textures and an OBJ loader.

The SDL2 native libraries are required and are not in this package

ASGL2 calls SDL2 through the managed ppy.SDL2-CS binding (which this package depends on and installs for you), but the native libraries themselves are not included. ASGL2 needs SDL2 2.0.18 or later, SDL2_ttf (text) and SDL2_mixer (sound). Without them your game fails at start-up with a DllNotFoundException (a game that only lacks SDL2_mixer runs, silently, if it uses SoundPool).

Windows

Put these 64-bit files next to your game's .exe (a .NET 10 program runs as 64-bit on 64-bit Windows):

File What it is Where to get it
SDL2.dll SDL2 SDL2-2.x.y-win32-x64.zip from https://github.com/libsdl-org/SDL/releases
SDL2_ttf.dll SDL2_ttf, used for text SDL2_ttf-2.x.y-win32-x64.zip from https://github.com/libsdl-org/SDL_ttf/releases
libfreetype-6.dll, zlib1.dll needed by older SDL2_ttf builds the same SDL2_ttf zip (newer builds have FreeType built in; then you do not need them)
SDL2_mixer.dll SDL2_mixer, used for sound (WAV, OGG, MP3 and FLAC are built in) SDL2_mixer-2.x.y-win32-x64.zip from https://github.com/libsdl-org/SDL_mixer/releases

The simplest way to copy them on every build is to put them in your project and mark them "Copy to output directory" (Copy if newer), or add this to your .csproj (the files are ignored on Linux, so it is safe for a cross-platform project):

<ItemGroup>
  <Content Include="native\SDL2.dll"          CopyToOutputDirectory="PreserveNewest" />
  <Content Include="native\SDL2_ttf.dll"      CopyToOutputDirectory="PreserveNewest" />
  <Content Include="native\libfreetype-6.dll" CopyToOutputDirectory="PreserveNewest" />
  <Content Include="native\zlib1.dll"         CopyToOutputDirectory="PreserveNewest" />
  <Content Include="native\SDL2_mixer.dll"    CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

Linux

Install the libraries from your distribution; ASGL2 finds them under their usual names (libSDL2-2.0.so.0, libSDL2_ttf-2.0.so.0, libSDL2_mixer-2.0.so.0). Ubuntu 22.04 or newer and Debian 12 or newer are recent enough.

Distribution Command
Ubuntu, Debian, Mint, Zorin, Pop!_OS sudo apt install libsdl2-2.0-0 libsdl2-ttf-2.0-0 libsdl2-mixer-2.0-0
Fedora sudo dnf install SDL2 SDL2_ttf SDL2_mixer
Arch, Manjaro sudo pacman -S sdl2 sdl2_ttf sdl2_mixer

Text needs a TrueType font: FontFinder looks in the usual font folders and falls back to DejaVu Sans, which most distributions install by default (fonts-dejavu-core on Debian/Ubuntu).

Running and shipping

  • dotnet run builds and runs your game on either system.
  • To give a game to players who do not have .NET, publish it self-contained: dotnet publish -c Release -r linux-x64 --self-contained (or -r win-x64) and ship the output folder. Linux players still install the SDL2 packages above; on Windows, ship the DLLs in the folder.
  • Sound stutters (most often in virtual machines)? Give the mixer a bigger buffer: set SoundManager.AudioBufferSize = 4096; before the first sound, or run the game with the environment variable ASGL_AUDIO_BUFFER=4096.

SDL2, SDL2_ttf and SDL2_mixer use the zlib license; FreeType and zlib have their own permissive licenses. Check their terms if you redistribute them with your game.

A first game

using ASGL2;
using SDL2;

public enum Screen { Play }

public sealed class MyGame : GameBase
{
    public override bool Initialize()
    {
        Renderer.Instance.Initialize("My game", new RendererSettings
        {
            LogicalWidth = 800,     // the drawing area; the window is scaled to fit it
            LogicalHeight = 480,
            WindowWidth = 1200,
            WindowHeight = 720,
        });
        ClearColor = SDLColors.FromRgb(20, 24, 40);

        SetLogicFPS(60);
        SetRenderFPS(60);
        RegisterState(Screen.Play, typeof(PlayState));
        ChangeGameState(Screen.Play, null);
        return true;
    }
}

public sealed class PlayState : BaseState
{
    public PlayState(object sender, object[] args) : base(sender, args) { }

    public override void Initialize() { }
    public override void Terminate() { }

    public override void GameLogic(object sender, SDL.SDL_Event e)
    {
        // once per logic tick (60 a second): input, movement, collisions
    }

    public override void Render(object sender)
    {
        // once per frame: draw with Renderer.Instance, sprites, tile maps, the UI...
    }
}

internal static class Program
{
    private static void Main()
    {
        new MyGame().StartGame();
    }
}

Fullscreen and sharp text

The window can be any size: the game draws at its logical size and SDL scales it to fit. Toggle fullscreen with Renderer.Instance.ToggleFullscreen(), and keep text crisp by rendering it at the window's scale:

font.RenderScale = TtfFont.OutputScale(Renderer.Instance.SDLRenderer);   // before drawing; only does work when it changes

Loading a tile map made with the map editor

TileMapData data = TileMapData.Load("Assets/Levels/level1.tilemap.json");
GenericTileMap map = data.CreateMap(Renderer.Instance.SDLRenderer, null, 800, 480, "Assets/Levels/level1.tilemap.json");
Point? start = data.FindSpawn("player");

// every logic tick:
map.UpdateTileAnimations();     // animated tiles (coins, water...) defined in the map file
// every frame:
map.Render(Renderer.Instance.SDLRenderer, 0, 0);

Upgrading from 2.x

ASGL2 3.0 is the cross-platform release. Most games only need to be retargeted to .NET 10 and given SDL2_mixer.dll; these are the changes that can affect existing code:

  • Targets .NET 10 (2.x targeted .NET Framework 4.8). Change your project's TargetFramework to net10.0.
  • Sound uses SDL2_mixer instead of CSCore (Windows only). Ship SDL2_mixer.dll (Windows) or install libsdl2-mixer-2.0-0 (Linux). WAV, OGG, MP3 and FLAC all play.
    • SoundManager.SetMasterVolulme / GetMasterVolulme are now SetMasterVolume / GetMasterVolume (the old names still work but are obsolete). Master volume and mute now apply to the game's own sound, not to the Windows volume.
    • Sound plays on one output device, chosen with SoundManager.DefaultDeviceIndex before the first sound (default: the system's default device).
    • LoopingVariableRateSound no longer takes an MMDevice; VariableRateLoopSampleSource and SoundManager.GetTempFolder() were removed.
  • Images are decoded by StbImageSharp instead of System.Drawing; the Surface(IntPtr, Bitmap) constructor was removed.
  • SoundPool.Play skips copies of an effect that are still playing (it used to try the next copy in turn whether or not it had finished), so rapid repeats no longer drop sounds while a free copy exists.

New in 3.0

  • Music: MusicPlayer streams one background track (OGG recommended) with looping, fade in/out, pause and its own volume.
  • Sound: SoundPool.Play(name, volume) plays an effect quieter for one play (distance-based volume); SoundPool.Add(name, byte[] data, fileType, ...) loads an effect from memory; SoundManager.IsPlaying; SoundManager.AudioBufferSize (or the ASGL_AUDIO_BUFFER environment variable).
  • Text: TtfFont passes text as UTF-8; TtfFont(renderer, byte[] fontData, size) opens a font from memory; TtfFont.RenderScale and TtfFont.OutputScale render text at the window's real resolution, so it stays sharp when the game is scaled up or fullscreen.
  • Embedded assets: SpriteSheet(renderer, ResourceInfo), GenericTileMap / IsometricTileMap constructors that take the sheet as a ResourceInfo, TileMapData.Parse(json, name) and TileMapData.CreateMap(..., ResourceInfo sheet).
  • UI and loop: Dialog.ShowModal / Dialog.AskModal (dialogs that wait for the answer) and GameBase.IsExiting / PumpInput / RenderFrame.

Documentation in this package

The package carries its documentation as plain Markdown in the docs/ folder (one page per area, generated from the same XML doc comments that IntelliSense shows), with docs/llms.txt as an index. That makes it easy to hand to an AI coding assistant: point it at llms.txt, or at the page for the area you are working on. The full guides, the demo games and their source are at https://asgl.ServeGame.com.

Requirements

  • .NET 10, on 64-bit Windows or Linux (x64; Linux on ARM64 should work with the distribution's SDL2 packages but is untested).
  • The SDL2 native libraries, which are not in the package (SDL 2.0.18 or later):
    • Windows: put SDL2.dll, SDL2_ttf.dll (with libfreetype-6.dll, zlib1.dll) and SDL2_mixer.dll next to your program.
    • Linux (Debian/Ubuntu): sudo apt install libsdl2-2.0-0 libsdl2-ttf-2.0-0 libsdl2-mixer-2.0-0 (see above for other distributions).
  • Dependencies installed automatically by NuGet: ppy.SDL2-CS, StbImageSharp.

License

MIT. See the license in the package metadata. The dependencies (ppy.SDL2-CS, StbImageSharp, SDL2, SDL2_ttf, SDL2_mixer) have their own licenses.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 132 11/6/2026
3.0.0 150 10/18/2026
2.0.1 141 10/3/2026 2.0.1 is deprecated because it is no longer maintained.
1.0.0 136 9/21/2026