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

global sprite aliases? #267

Open
reececomo opened this issue Jun 19, 2024 · 0 comments
Open

global sprite aliases? #267

reececomo opened this issue Jun 19, 2024 · 0 comments

Comments

@reececomo
Copy link

It would be neat if one could somehow alias audio sprites globally, similar to the texture cache for Spritesheets.

// Assume we've loaded two sound sprites:
//   - mySoundSprite1.sprites: [ 'laugh, 'sneeze' ]
//   - mySoundSprite2.sprites: [ 'boo', 'cheer', 'cry' ]

import { sound } from '@pixi/sound';

sound.play('boo', { volume: 0.75 });
sound.play('laugh', { volume: 0.5 });

It would make working with multiple audio sprites a lil slicker. As a workaround we've got something like this:

import { sound as pixiSound } from '@pixi/sound';
import { Music, SoundFx } from './my-assetpack-generated-constants';

export class SoundManager {
  /** reverse map of children -> parents */
  public childSpriteAliases = Map<Sounds, string>();

  public async play(alias: Music | SoundFx, options: PlayOptions = {}): Promise<IMediaInstance | undefined> {
    const parentSound = this.childSpriteAliases.get(alias);

    // play sprite
    if (parentSound) {
      return pixiSound.play(parentSound, { ...options, sprite: alias });
    }

    // play other ...
    return pixiSound.play(alias, options);
  }

  // ...
}

(And then in our audiosprite loader we've added some custom logic to inject those aliases on load.)

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

1 participant