Sounds and music
How to play, pause, resume, edit, and stop sounds and music in Pixi’VN using media, channels, and the sound manager, including fade transitions and filters, built on Tone.js.
The entire audio system has been revised in version 1.6.0/1.8.0.
The sound module is a wrapper around the Tone.js library. It provides a simple interface for playing sounds and saves the current state at each step.
ink
Sie können diese Methode mit der ink-Syntax verwenden. See more here.
import { narration, newLabel, sound } from "@drincs/pixi-vn";
export const startLabel = newLabel("start", [
async () => {
await sound.play("sfx_whoosh", { delay: 0.1 });
await sound.play("bgm_cheerful", { loop: true, channel: "bgm" });
narration.dialogue =
"Hello, I'm a cheerful background music that will loop forever until you stop me.";
},
() => {
sound.pause("bgm_cheerful");
narration.dialogue = "I'm paused, but I can be resumed.";
},
() => {
sound.resume("bgm_cheerful");
narration.dialogue = "I'm back!";
},
]);Initialisierung
It is also recommended to define channels immediately after game initialization. To do this, you can use the sound.addChannel function.
import { Game, sound } from "@drincs/pixi-vn";
Game.init(body, {
// ...
}).then(() => {
sound.addChannel("bgm", { background: true });
sound.addChannel("sfx");
sound.defaultChannelAlias = "sfx";
});Play
If no channel is specified during the play function, the media will be assigned to sound.defaultChannelAlias.
The basic functionality is to start a sound (asset). This can be done using the play function. The play function generates a media instance that you can interact with to control the produced sound.
Transitions
Pause and resume
There are various ways to pause individual or multiple media.
Bearbeiten
Only media settings will be saved in game save files.
It is possible to edit almost all settings at any time for different purposes.
Stop
To stop a sound, you can use the stop function.
Filters
Currently, they can only be modified when starting a media.
Filters are elements that allow advanced customization of sounds.