Skip to content
Black Ram edited this page Aug 18, 2024 · 1 revision

Sounds and Music

The sound module is a wrapper around the PixiJS Sound library. It provides a simple interface for adding and playing sounds.

The principal functions are:

Add and Playing

Creation of a sound is simple. You can also use the PIXI.sound library methods (add, play) for adding and playing a sound as well.

import { sound } from '@drincs/pixi-vn'

// In this case, you create a simple sound, and play it with loop
sound.add('bird', 'resources/bird.mp3');
sound.play('bird', {
    loop: true,
});

// This case is the same as above, but you can use the sound object
let s = sound.add('bird', 'resources/bird.mp3');
s.play({
    loop: true,
});

// In this case, you create a loop sound, and play it
let s = sound.add('bird', {
    url: 'resources/bird.mp3',
    loop: true,
});
s.play();

Pause and Resume

You can pause and resume a sound.

import { sound } from '@drincs/pixi-vn'

let s = sound.add('bird', 'resources/bird.mp3');
s.play();
s.pause();
s.resume();

Stop

You can stop a sound.

import { sound } from '@drincs/pixi-vn'

let s = sound.add('bird', 'resources/bird.mp3');
s.play();
s.stop();

Volume

Volume can be set initially by using the object constructor

import { sound } from '@drincs/pixi-vn'

let s = sound.add('bird', {
    url: 'resources/bird.mp3',
    volume: 0.5,
});
s.play();

Volume can also be set by changing the volume property.

import { sound } from '@drincs/pixi-vn'

let s = sound.add('bird', 'resources/bird.mp3');
s.volume = 0.5;
s.play();

Filters

You can add filters to a sound.

import { sound, filters } from '@drincs/pixi-vn'

let s = sound.add('bird', 'resources/bird.mp3');
s.filters =  [
    new filters.StereoFilter(),
    new filters.ReverbFilter(9, 2)
]
s.play();
Clone this wiki locally