@antha/audio
v0.6.1
Published
An Antha mod for handling audio.
Readme
@antha/audio
This package provides a pre-built Antha game engine mod for loading and playing audio in the browser.
Install
npm i @antha/audioUsage
import {AnthaEngine, defineAnthaMod} from '@antha/engine';
import {type AnthaAudioState, createAnthaAudioMod} from '@antha/audio';
type GameState = AnthaAudioState & {
shouldPlayJumpSound: boolean;
};
const engine = new AnthaEngine<GameState>({
initState: {
shouldPlayJumpSound: true,
},
mods: [
createAnthaAudioMod(),
defineAnthaMod<GameState>({
modName: 'game-logic',
execute({state}) {
if (state.audioPlayer && state.shouldPlayJumpSound) {
state.shouldPlayJumpSound = false;
void state.audioPlayer.play({
sources: [
'/audio/jump.ogg',
'/audio/jump.mp3',
],
});
}
},
}),
],
});
engine.startLoop();