Le son permet de donner une identité sonore au jeu et favoriser l'immersion du joueur.
Charger un son
load.jsconst 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.jsscene("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) })