Preloading sounds in script

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Grenade Sound Library contains: 135 sounds 50 grenade sounds and 85 surface sounds
  • So based on the audio scripting example, I have to manually (pre)load the audio myself in order to use it. In the example it's done like so

    [audioSfx5, audioSfx7, audioEpicArpg] = await Promise.all([
    		audioManager.loadSound("sfx5.webm"),
    		audioManager.loadSound("sfx7.webm"),
    		audioManager.loadMusic("epicArpg.webm")
    	]);

    I have many many more sounds. Surely there's a better way to do this. But... no? The best way I found was with a loop but I still have to punch in every single soundfile myself. Is there really no way to just get all the soundfiles to preload like the audio plugin usually does by itself?

    I thought the asset manager would help, but also no...

    construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/interfaces/iassetmanager

    Am I just overlooking something or is this a case for a feature request?

    And of course I had to do some snooping around... the closed off internal asset manager has the exact function I need. GetAudioToPreload()

    But of course I can't use that :,)

  • You don't need to extend that code for every sound file - an array with just a list of filenames should suffice, and you could do something like build a map of filename to loaded audio from that.

    I would say Construct's option to preload all sound is a pretty blunt instrument, particularly for large projects. With scripting it's easier to do better and do things like group sound files in to sets that are loaded and unloaded all together - in which case you'd need to write arrays of paths anyway. I guess we could add a script API to list all files the project was exported with, but then it won't reflect changes made after export, which I'm sure would end up tripping some people up.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Maintaining that for potentially 100s of files still sounds kind of like a nightmare. Couldn't the sorting/grouping be largely reflected by the folder structure? For example if I put a goblin on a layout I need all sounds that belong to the goblin which are all sorted in "enemies/goblin/..."

    If I then had access to this folder structure I could just loop through all files inside that folder without having to maintain an extra list. I can do that additionally if I need to though or even tack on some extra files if needed.

    But even getting an array of all files would suffice though since I can just run a filter over it to get all the file paths that contain "enemies/goblin/" and loop over that.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)