IO topic

IO Module

ResourceManager

The ResourceManager simplifies loading assets. Assets are loaded asynchronously and the API is identical on web and SDL3.

On web, assets are fetched via HTTP. On SDL3, they are loaded from the filesystem (relative to the working directory or executable location).

How to render a progress bar during loading?

Loading assets

Function Description
loadTexture(String path) Loads an image file as a Texture. Caches textures by path.
loadImage(String path) Loads an image (and optionally slives it into frames)
loadFont(String path, double size) Loads a font file (e.g., TTF, OTF) and prepares a BitmapFont instance.
loadSound(String path) Loads an audio file.
loadString(String path) Loads the contents of the path into a String.

All load* methods return the asset handle (Texture, Images, BitmapFont, Sound) immediately. The actual loading is asynchronous. You can already use the handles even if loading is unfinished. For example if you draw an Texture/Image while it is still loading, the render call ist just ignored. If you have the loader enabled (which is the default behaviour) you can be sure in your onUpdate/onRender methods that all assets are finished loading and ready for usage.

Loading a font

var font = resources.loadFont("assets/fonts/wireone/WireOne-Regular.ttf", 196);

// Drawing text with loaded font
gfx.drawText(font, "Drawing some letters to the screen...", x: 25, y: 25);

Loading an image / spritesheet

// Loading a sheet of 16x16 sprites
var spritesheet = resources.loadImage(
  "assets/spritesheet.png", frameWidth: 16, frameHeight: 16
);

// Drawing frame 0 of spritesheet at position 16, 16
gfx.drawImage(spritesheet, 0, 16, 16)

Loading a sound

// Load a sound
var shootFX = loadSound("assets/shoot.wav", retriggerDelayInMs: 50);

// Start playing the sound
audio.playSound(shootFX);

Playing music

// Loading a music file is not required, you can directly play it
// and it will be streamed in the background as soon as possible.
audio.playMusic("assets/music.ogg", true);

Classes

Loader IO
Manages and tracks the progress of multiple asynchronous loading operations.
LoaderItem IO
An individual item being tracked by the Loader.
LocalStorage IO
A utility class for persistent key-value storage.
ResourceManager IO
Manages the loading of game resources such as textures, images, fonts, and sounds.

Functions

loadStringAsync(String url, Loader loadingInfo, {FileBackend? fileBackend}) Future<String> IO
Asynchronously loads a string from the specified url.