Skip to main content

Asset

The Asset type represents an asset file such as an image or sound. Assets can be specified using a @ symbol followed by the filename. If there are multiple files with the same filename, the file which is closest to the current file will be selected.

// Refer to assets by their filename with an @ prefix before the string
// This will be resolved at compile time and will error at compile time if it does not exist
Image(@fireball.svg) // displays the image in the UI
ImageSprite(@fireball.svg) // renders the image as a sprite in-game

Sing(@fireball.esfx) // plays the sound but stops if this entity dies
Hear(@fireball.esfx) // plays the sound to completion

Folders

You can include folders in your asset path to help disambiguate between assets with the same name. For example, in a project where @image.svg could refer to multiple files, you could use @fireball/image.svg or @thunderbolt/image.svg to be more specific.

Wildcards

You can use wildcard patterns to match multiple files, for example @fireball-*.svg will match fireball-1.svg and fireball-2.svg. A constant Array containing all matching files will be returned. Wildcard patterns are resolved at compile time and so are an efficient way of handling large numbers of similar assets.

Like any other Array, you can access each element by index:

let fireballImages = @fireball-*.svg
ImageSprite(fireballImages[0])

You can iterate over the array of assets to create animations:

for image in @fireball-*.svg {
ImageSprite(image)
await Tick
}

Alternatively, the Array can be passed directly to the ImageSprite function to create an animation:

ImageSprite(@images/fireball-*.svg, frameInterval=0.1s)

At present, wildcards are not supported in the middle of a path, only at the end. They only match filenames, not folder names.