Skip to content
Browse Docs and Help
how-to

Load project images, sounds and level data

Use local asset helpers and static imports instead of network access.

On this page

Images and sounds

Upload media through Studio Assets or include accepted media in the project. The SDK asset path format currently accepts PNG images and WAV sounds.

import llvls from '@llvls/sdk';

await llvls.init();
const hero = new Image();
hero.src = llvls.assets.url('assets/images/hero.png');
await hero.decode();
// Draw hero once the game is ready.

This fragment requires the named image to exist. assets.url() validates the path and returns a URL synchronously; it does not prove the file exists. Handle loading failures.

For decoded sound:

import llvls from '@llvls/sdk';

await llvls.init();
const bytes = await llvls.assets.bytes('assets/audio/jump.wav');
const audio = new AudioContext();
const buffer = await audio.decodeAudioData(bytes);
// Resume audio only after ready() and apply the host's mute/pause state.
void buffer;

The audio fragment does not implement playback or host audio events. Add the lifecycle handling described in the audio guide.

Level data

Import project JSON statically, for example import level from './level.json', and validate its expected shape before use. Do not use assets.bytes() for JSON: it accepts PNG images and WAV sounds.

Restrictions and failures

No remote URLs, CDNs, font files or SVG uploads. Do not call fetch yourself. Missing byte assets reject with not_found; invalid paths use invalid_argument. Handle both without falsely reporting that all assets loaded.

An import may convert and rename media. Update source references to match the actual project paths.