Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound in new Library shares the same filters set in default library #183

Open
yueyuzhao opened this issue Jan 1, 2022 · 5 comments
Open

Comments

@yueyuzhao
Copy link
Contributor

Hi there,

I'm creating a new SoundLibrary called uiLib, but the sounds added to uiLib are also applying the filters set to the default library sound. But I don't think filters set to A library should apply to B library, isn't it?

But from the code

sound/src/Sound.ts

Lines 355 to 362 in a7f6706

/**
* Instance of the media context
* @type {IMediaContext}
*/
public get context(): IMediaContext
{
return getInstance().context;
}

We can see that all sounds are sharing the same audio context from the default library sound. Is this a bug or not?

Meanwhile, it seems that I can call setInstance when adding sounds to uiLib, then switch it back to sound, but setInstance is not exported.

@bigtimebuddy
Copy link
Member

bigtimebuddy commented Jan 1, 2022

This is not really intended usage to create a new SoundLibrary.

Are you trying to separate UI from other audio? This feature request has come up a bunch. I suggest we add groups for doing UI, FX, music, etc.

@yueyuzhao
Copy link
Contributor Author

In my opinion a simple way to solve this is : add a private field _context to Sound, pass the audio context to Sound when creating, if the passed context is null, then use the audio context in the default library.

I don't think I understand groups, would you mind explain the concept of groups?

@bigtimebuddy
Copy link
Member

Groups would allow a user to add filters, set volume, mute, pause, etc a user-defined set of sounds. It's very common to do this kind of thing with games.

sound.addGroup("ui", ["beep", "boop"])
sound.groupVolume("ui", 0.5)
sound.groupFilters("ui", [])

@yueyuzhao
Copy link
Contributor Author

Thank you for your explanation, but it seems another SoundLibrary.

I assume Group can

  • manage sounds (sounds in a group sharing a same audio context)
  • set volume
  • set filters
  • play controls (pause, resume, stop)

Then what's the difference between Group and SoundLibrary?

I have little experience in game development, but I can't find the Group implementation in Phaser either, is there any project that did what you said?

Thanks and happy new year!

@yueyuzhao
Copy link
Contributor Author

Hi @bigtimebuddy , I read the thread #74, but I still don't think introducing group for this is a good idea. A sound created by Sound.from which is not added to the library shares the context of the default sound library and has all the filters set to the default library, this definitely confuses users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants