Skip to content
Docs
Games

Assets

Import images and sounds, and use them for avatars, sounds and the UI.

Assets are the images and sounds your game uses: a texture for the ball, a goal sound, a logo in the Menu. They live in your project folder next to your code, and they ship inside your release.

You add an asset by importing it, just like a module. The import doesn't give you the file's contents. It gives you a small reference you pass to disko. The players' browsers download the file itself only when they need it.

Importing art/puck.png gives a reference. The game passes it to disko, for example as a disc avatar, which tells players' browsers which asset to show. The browsers download puck.png from the room when they need it.

Importing an asset

An asset is packaged only if a module imports it (see What goes into a release), and only with a default import:

src/main.ts

The value you get is a frozen object such as { kind: "package-asset", name: "art/puck.png" }, where name is the file's path in the project. Importing the same file twice gives the same object.

Only the default import form works. Named imports, import * as, and importing a file just for its side effects are rejected (asset_import_form). You may re-export one, though: export { default as puck } from "./art/puck.png".

Using an asset

Pass the reference wherever disko accepts an asset: disc.setAvatar or player.setAvatar for images on discs, game.playSound for sounds, and ui.image({ asset }) in the Menu or HUD.

src/main.ts

Supported formats

ExtensionType
.pngimage/png
.jpg, .jpegimage/jpeg
.webpimage/webp
.mp3audio/mpeg
.oggaudio/ogg
.wavaudio/wav
  • Extensions must be lowercase, and SVG isn't supported.

  • A file's contents must match its extension: a JPEG renamed to .png is rejected (asset_content_mismatch).

  • Images can be 1 to 4096 pixels per side (image_dimensions), and each asset at most 16 MiB.