Canvas UI, Web Audio, Timers & Persistence
Buttons, sound effects, smooth popups, particle sparks, and saving progress are what turn a tech demo into a real game.
Maverick bundles all of these without needing React, external audio libraries, or manual setTimeout hacks.
Without Built-in UI, Audio Buses & Pause-Safe Timers
Clicking a "Buy Potion" button on an HTML overlay can accidentally fire your hero's sword underneath.
Browser setTimeout keeps ticking even when the player pauses the game, raw localStorage
breaks when you update your save format, and overlapping sounds distort without volume mixing.
Why Maverick Built These Systems
game.UI catches clicks before gameplay sees them. Sounds gives you a studio mixing board
(master, sfx, music). Timers/Tweens freeze automatically when paused,
and SaveManager versions your player's save slots safely.
1. Retained Canvas UI & Wrapped Text
Retained UI means you create a button once (new UIButton(...)) and Maverick remembers
where it is, highlights it on hover, and blocks clicks from leaking through to your game world—just like real in-game menus.
import { UIButton, UILabel, UIPanel, UIProgressBar, UIStack } from 'maverick';
const stack = new UIStack({
id: 'hudStack',
bounds: { x: 16, y: 16, width: 220, height: 140 },
spacing: 10,
padding: 12,
});
stack.addChild(new UILabel({ id: 'title', bounds: { x: 0, y: 0, width: 196, height: 24 }, text: 'RPG Store' }));
stack.addChild(new UIProgressBar({ id: 'hp', bounds: { x: 0, y: 0, width: 196, height: 14 }, value: 0.75 }));
stack.addChild(new UIButton({
id: 'buyBtn',
bounds: { x: 0, y: 0, width: 196, height: 36 },
label: 'Buy Potion (25g)',
onClick: () => this.Sounds.play('coin', { bus: 'sfx' }),
}));
this.UI.add(new UIPanel({ id: 'hudBg', bounds: { x: 16, y: 16, width: 220, height: 140 }, zIndex: 0 }));
this.UI.add(stack);
2. Web Audio Buses (master, sfx, music)
Think of audio buses like sliders on a DJ mixing board: you can turn down background music to 40%
while keeping coin pickups crisp at 80%, or mute everything at once with master—without editing every sound call.
this.Sounds.addSource('coin', './assets/coin.wav');
this.Sounds.addSource('bgm', './assets/town.ogg');
await this.Sounds.preload();
this.Sounds.setBusVolume('sfx', 0.8);
this.Sounds.setBusVolume('music', 0.4);
await this.Sounds.playMusic('bgm');
await this.Sounds.play('coin', { bus: 'sfx' });
3. Pause-Aware Timers, Tweens, Signals & Particles
A Tween smoothly slides a number from A to B (like a card popping onto screen), a Signal
is a radio broadcast that notifies your HUD whenever gold changes, and a ParticleEmitter bursts
dozens of tiny sparks when you buy an item or land a hit. Best of all, Timers and Tweens
automatically freeze when the player pauses!
import { Easing, ParticleEmitter, Signal } from 'maverick';
const onGoldChanged = new Signal<number>();
onGoldChanged.connect((gold) => console.log('Gold:', gold));
this.Timers.after(1.5, () => onGoldChanged.emit(100));
this.Tweens.to(cardPos, { y: 40 }, 0.4, Easing.easeOutQuad);
const sparks = new ParticleEmitter({ maxParticles: 60, lifetime: 0.4, gravityY: 200 });
sparks.emit(120, 80, 15);
4. Asset Manifest & Versioned Save Slots
AssetManifestLoader loads all your images and sounds in one batch with a 0–100% progress bar for loading screens.
SaveManager saves player progress to browser storage with a version number, so future game updates never crash old saves.
import { AssetManifestLoader, SaveManager } from 'maverick';
await AssetManifestLoader.load(
{ images: { hero: './hero.png' }, sounds: { coin: './coin.wav' } },
this.Sprites,
this.Sounds,
(p) => console.log(`Loading: ${Math.round(p.progress * 100)}%`)
);
const saves = new SaveManager('my_rpg', 1);
saves.save('slot1', { level: 3, gold: 250 });
const loaded = saves.load<{ level: number; gold: number }>('slot1');
game.UI, Web Audio, Tweens, Particles & SaveManager