Assets
Bare has three ways to get images into your game. Pick per image, and switch between them without changing your code.
| Where | When it loads | Good for |
|---|---|---|
texturePackImages/ | Packed into an atlas, loaded before the game starts | Small images used right away (UI, player) |
public/initial/ | Loaded before the game starts | Anything that must be ready at once |
public/images/ | Streamed in when first used | Everything else, especially large images |
In code you always refer to an image by name. The engine looks for it in the initial assets first, then streams it from public/images/:
this.AddGameObject('gear');Texture atlas
While the dev server runs, every image in texturePackImages/ is packed into one atlas in public/initial/generated/. Add, change or remove an image and the atlas updates automatically.
Streaming images
Put .webp images in public/images/, in subfolders if you like. A GameObject using a streamed image appears as soon as its image has loaded. Prefabs can point to a subfolder with imagePath:
{
"name": "saw",
"imagePath": "enemies",
"texture": "saw"
}To wait for an image yourself:
await bare.asset.LoadTexture('backgrounds/sky');See bare.asset for all methods.
Examples: the Showcase's image loading demo, and the Platformer, which streams in everything, including animations.
Generated assets
The dev server writes src/generated/assets.ts with a typed list of your assets:
import { Asset } from './generated/assets';
this.AddGameObject(Asset.Image.EMOJI_GEAR);
bare.sound.Play(Asset.Sound.JUMP);
bare.level.Load(Asset.Level.LEVEL_1);Don't edit this file; it's regenerated whenever your assets change.
Sounds
Put .mp3 files in public/sounds/ and play them by name. They load on first use:
bare.sound.Play('jump');
bare.sound.Play('music', { loop: true, volume: 0.5 });See Sound.
Example: the Showcase's sound demo registers a sound with a different file name and plays it with a random pitch.
Fonts
Put fonts in public/fonts/ and load them by name (.ttf by default):
await bare.LoadFont('myFont');Example: the Platformer's UI loads a font and an image before it shows the coin counter.
Animations
Frame animations are defined in settingsData.json, and their frames load like any other image. See Animations.