my folder structure is:
root - assets - sounds -(sounds.ac3,sounds.json,sounds.m4a,sounds.mp3,sounds.ogg)
root - src - scenes - mainscene.ts
i tryed to load my audioSprite like that:
this.load.audioSprite(‘sounds’, ‘./assets/sounds/sounds.json’);
then in create:
let music = this.sound.addAudioSprite(‘sounds’);
my sounds.json looks like:
{
“resources”: [
“sounds.ogg”,
“sounds.m4a”,
“sounds.mp3”,
“sounds.ac3”
],
“spritemap”: {
“alarm”: {
“start”: 0,
“end”: 3.526530612244898,
“loop”: false
},
“Buton”: {
“start”: 5,
“end”: 5.051609977324263,
“loop”: false
}
}
}
and i get this error: TypeError: this.jsonCache.get(…) is undefined
Audio cache entry missing: sounds
this kind of format works in javascript.
i spent some time to this error.
can someone help me?
yannick
2
I have tested it with TypeScript and Phaser 3.16.2 and it worked great.
The only thing I have adjusted was the path in the resources array of sounds.json
{
"resources": [
"assets/sounds/sounds.ogg",
"assets/sounds/sounds.m4a",
"assets/sounds/sounds.mp3",
"assets/sounds/sounds.ac3"
],
"spritemap": {
"alarm": {
"start": 0,
"end": 3.526530612244898,
"loop": false
},
"Buton": {
"start": 5,
"end": 5.051609977324263,
"loop": false
}
}
}
Like this in your scene and the alarm sound should play for 3.5 seconds.
preload() {
this.load.audioSprite('sounds', 'assets/sounds/sounds.json')
}
create() {
this.sound.addAudioSprite('sounds')
this.sound.playAudioSprite('sounds', 'alarm')
}
1 Like
Thank you! I see now, the path must be set from the .json file too.