Ajouter un fond sonore

Le son permet de donner une identité sonore au jeu et favoriser l'immersion du joueur.

Charger un son

load.js
const MP3 = [ "tough zombeat" , "wooosh" , "off" , ]

Créer un nouveau composant

component.js
// Ajoutes ici tes propres composants
function music(config) { const param = { volume: 1.0, ...config } return { audio: null, add() { if (param.music) { this.audio = play(param.music, { loop: true, volume: param.volume }) onSceneLeave(() => this.audio.stop()) } } } }

Modifier un objet dans la scène

game.js
scene("game", () => { // scène dans laquelle se déroulent les niveaux const config = { ...LEVEL_CONFIG, ...LEVELS[CURRENT_LEVEL].config } const utilities = add([ music(config), multiplayerCamera(), ]) setGravity(3200) setBackground(config.backgroundColor) addLevel(LEVELS[CURRENT_LEVEL].map, config) })

Configurer les niveaux

levelConf.js
const LEVEL_CONFIG = { // paramètres du niveau
music: "tough zombeat", volume: 1,
tileWidth: 64, tileHeight: 64, gravity: 3200, tiles: { // listes des objet à placer dans les niveaux "#": () => [ // player sprite("bean"), platformerController(), alive(), opacity(), scale(), health(1, 4), area(), anchor("bot"), body(), respawn(), falling(), coloring(), animator(), ], "=": () => [ // block sprite("grass"), area(), body({ isStatic: true }), anchor("bot"), offscreen({ hide: true }), ], }, }