@samme : what am I doing wrong here?
I’m getting :
Error: There is no audio asset with key "bgMusic" in the audio cache phaser.js:83761:19
But I have all the right files in the right folders media-wise & i’m calling their correct locations in code as well.
this.__BGMTrack = [ ];
this.__BGMData = [ ];
this.__SFXTrack = [ ];
this.__SFXData = [ ];
this.__BGMAudio = [ ];
this.__SFXAudio = [ ];
this.countJSObjectData = function ( __objData ) {
this.__objData = __objData;
return Object.keys ( this.__objData ).length;
}
this.__preload = function ( ) {
// Load Background Music File{s}
this.__BGM_Data = {
ids : [
'bgMusic', 'lvl1Music', 'lvl1MusicA',
'lvl2Music',
],
files : [
'assets/TownTheme.mp3',
'assets/TownTheme2.mp3',
'assets/bgm/lvl-1/SMILE.mp3',
'assets/bgm/lvl-1/smb-overworld-remix.mp3',
],
};
this.__SFX_Data = {
ids : [
'jumpA',
],
files : [
'assets/bgm/lvl-1/SMILE.mp3',
],
};
// Create & Load our BGM{s}
this.__BGMTrack = [
'bgMusic', 'lvl1Music', 'lvl1MusicA',
'lvl2Music',
];
this.__BGMData = [
{
volume : 0.1, loop : true,
},
{
volume : 0.1, loop : true,
},
{
volume : 0.03, loop : true,
},
{
volume : 0.1, loop : true,
},
];
// Create & Load our sound{s}
this.__SFXTrack = [
'jumpA',
];
this.__SFXData = [
{
volume : 0.1, loop : true,
},
];
this.__BGM_Data_Length = ( countJSObjectData ( this.__BGM_Data.files ) );
this.__SFX_Data_Length = ( countJSObjectData ( this.__SFX_Data.files ) );
for ( this.__i = 0; this.__i < ( this.__BGM_Data_Length ); this.__i++ ) {
console.log ( 'Data IDs :: ' + this.__BGM_Data.ids [ this.__i ] );
}
for ( this.__i = 0; this.__i < ( this.__SFX_Data_Length ); this.__i++ ) {
console.log ( 'Data IDs :: ' + this.__SFX_Data.ids [ this.__i ] );
}
for ( this.__i = 0; this.__i < ( this.__BGM_Data_Length ); this.__i++ ) {
console.log ( 'Data Files :: ' + this.__BGM_Data.files [ this.__i ] );
}
for ( this.__i = 0; this.__i < ( this.__SFX_Data_Length ); this.__i++ ) {
console.log ( 'Data Files :: ' + this.__SFX_Data.files [ this.__i ] );
}
console.error ( this.__BGM_Data_Length );
console.error ( this.__SFX_Data_Length );
this.LoadAudio = function ( __objData )
{
this.__objData = __objData;
this.__masterKey = this.__objData.masterKey;
if ( typeof ( this.__objData ) !== 'object' ) { return console.error ( 'ERROR :: { Please ensure you are using an `object` for `objectData` & try again } !' ); }
this.__snd = this.__objData.sound;
this.__soundID = this.__objData.soundID;
this.__soundData = this.__objData.soundData;
console.error (
'this.__soundID' + ' :: ', this.__soundID + '\r\n' +
'this.__soundData' + ' :: ', JSON.stringify ( this.__soundData )
);
this.__sound = this.__snd.add ( this.__soundID, this.__soundData );
console.error (
'this.__snd' + ' :: ', this.__snd
);
return this.__sound;
}
this.IsSoundPlaying = function ( __sound )
{
this.__sound = __sound;
return this.__sound.isPlaying;
}
this.StopAudio = function ( __sound )
{
this.__sound = __sound;
if ( typeof ( this.__sound ) !== 'object' ) { return console.error ( 'ERROR :: { Please ensure you are using an `object` for `objectData` & try again } !' ); }
this.__sound.stop ( );
}
this.PlayAudio = function ( __objData )
{
this.__objData = __objData;
this.__scene = this.__objData.scene;
this.__snd = this.__objData.sound;
this.__soundID = this.__objData.soundID;
console.log ( this.IsSoundPlaying ( this.__snd ) );
if ( this.IsSoundPlaying ( this.__snd ) === true ) {
this.StopAudio ( this.__snd );
this.__snd.play ({
seek : 0,
});
}
if ( this.IsSoundPlaying ( this.__snd ) === false ) {
this.__snd.play ({
seek : 0,
});
}
}
this.SwitchAudio = function ( sound, current, next )
{
this.__sound = sound;
this.__current = current;
this.__next = next;
if ( this.__current.isPlaying ) {
this.__current.stop ( );
this.__sound.remove ( this.__current );
}
this.__current = this.__next;
this.__current.play ( );
}
for ( this.__i = 0; this.__i <= ( this.__BGM_Data_Length ); this.__i++ ) {
__BGMAudio [ this.__i ] = this.LoadAudio ({
sys : this.sys,
sound : this.sound,
soundID : this.__BGMTrack [ this.__i ],
soundData : this.__BGMData [ this.__i ],
});
console.error ( '__BGMAudio' + ' :: ', __BGMAudio );
}
for ( this.__i = 0; this.__i <= ( this.__SFX_Data_Length ); this.__i++ ) {
__SFXAudio [ this.__i ] = this.LoadAudio ({
sys : this.sys,
sound : this.sound,
soundID : this.__SFXTrack [ this.__i ],
soundData : this.__SFXData [ this.__i ],
});
console.error ( '__SFXAudio' + ' :: ', __SFXAudio );
}
}
this.__create = function ( ) {
// Start playing 1st BGM audio track in BGM Array :
/*
this.PlayAudio ( {
scene : this.__scene,
sound : __BGMAudio [ 0 ],
soundID : __BGMAudio [ 0 ].soundID,
}, 1 );
// Switch this from 1st BGM audio file in Array
// to 1st SFX audio file in Array on purpose :
// this.SwitchAudio ( this.sound, __BGMAudio [ 0 ], __SFXAudio [ 0 ] );
*/
}
this.__update = function ( ) {
}
this.__config = {
type : Phaser.AUTO, width : 800, height : 600,
physics : {
default : 'arcade',
arcade : {
gravity : {
y : 0,
}
}
},
scene : {
preload : this.__preload,
create : this.__create,
update : this.__update,
}
}
this.__game = new Phaser.Game ( this.__config );