FMOD Library Integration

Hi, I’m new to Phaser, with an intermediate programming background. I’m wondering, is there a standard way to load 3rd party libraries in Phaser? I have fmodstudio.js up and running, the initialization called during preload, but this is currently happening where the scene starts before the library is finished initializing. It would be great if the scene’s create could wait for a loading callback before this happens.

It’s impossible for Phaser to know when 3rd party scripts have completed doing whatever they’re going to do. All it can do is check that they’ve loaded and have been added to the DOM, after which create is run, but if they then go on to do something else, it’s up to you (or the script) to provide a callback to signal this. Have a look to see if FMOD provides some kind of callback like this, most libs do.

Thanks so much for your response, I do have an onload callback function set up. How would I connect this to the loader? Also, I want to check if all audio banks are loaded, but there’s no callback in the FMOD API for this, so it looks like the only option is to check this manually. I’m guessing this step would be best handled after create? Edit: Ah I re-read your post and what you’re saying is, I should have the game’s logic wait for this callback after create?

If create has run, then the library script file has loaded and been added to the DOM. What it sounds like is that FMOD then does other stuff asynchronously after it has loaded. I’ve no idea what, but most things with the Web Audio API are async, so it could be all of that. Suffice to say, you’re going to need a way to determine when FMOD has finished doing whatever it does before it can be used.

Yes, sorry I wasn’t clear about that, this is after the file has been loaded and added to the DOM. In a script, you have to create a blank object, assign callback functions, and pass the object into an FMODModule constructor that injects everything into it, then it initializes asynchronously. Then you have to create a StudioSystem instance and load sound banks with it. Could this be ideal? - Make a separate creation function that fires after both the scene’s create and FMOD’s async setup sends the finish callback.

Personally I would use the FMOD “I’m finished” callback to set a flag somewhere saying it’s ready to use (unless the API itself already provides a property for this?) - then in your create you can check this flag, and if set, go ahead and make all the sound banks, etc. If not, then you hold off doing this until that callback is invoked. I would do this as part of a Boot or Preloader Scene, it wouldn’t be my game scene, as it’s all set-up stuff. Once both parts are ready, I’d move to the game / main menu scene.

Thanks, I like the idea of a ‘Preloader’ scene! What I ended up doing since the last post was create the Phaser.Game and handle all FMOD loading (FMOD + Sound Banks) before creating the first scene.
The only ‘gotcha’ here is that the game now won’t load anything until the user makes a gesture on screen, since the audio engine is suspended until the user makes a gesture in Chrome/iOS (all bank loading must have the FMOD studio system engine running), so I’m going to incorporate your suggested loading scene idea, with a ‘start’ button that will appear (assuring an interaction). Then when the user clicks the screen, banks will begin loading. After banks are loaded, the next scene will start.