sound icon indicating copy to clipboard operation
sound copied to clipboard

Feature: Automatically Add Sound Sprites via `loadBundle`

Open furic opened this issue 1 year ago • 0 comments

It would be great if Assets.loadBundle() in Pixi could automatically handle sound spritesheets, making asset management even more efficient. I’ve submitted a related feature request in Pixi’s Asset Pack to support packing sounds into a sound spritesheet.

The idea is for Pixi to recognize a sound spritesheet in the bundle assets and automatically add the sound sprites based on the provided sounds.json file.

Here’s an example of how this could work:

// Init the manifest
 await Assets.init({
     manifest: {
         bundles: [
             {
                 name: 'load-screen',
                 assets: [
                     {
                         name: 'sounds',
                         srcs: 'sounds.json'
                     },
                 ],
             },
             ...
         ],
     },
 });
 
 // Load the bundle
const loadingScreenAssets = await PIXI.Assets.loadBundle('loading-screen');

// Create a new sound
const sound = PIXI.sound.Sound.from(loadingScreenAssets.sounds);

// Pixi should automatically recognize the sound spritesheet and add all sprites
// No need for explicit sound.addSprites({...})

// Use the sprite alias to play
sound.play('bgm_main');

Here’s a sample sounds.json file:

{
    "sprites": {
        "bgm_main": [0, 10, true], /* true for looping */
        ...
    },
    "srcs": {
        "./sounds.ogg",
        "./sounds.mp3",
    }
}

This feature would streamline the process by eliminating the need to manually call sound.addSprites({...}), allowing for more seamless sound management in Pixi.

furic avatar Oct 02 '24 01:10 furic