Add volume control to audio clips

This commit is contained in:
Evan Pratten 2020-04-18 16:01:13 -04:00
parent 44944626ef
commit f11bdb4892
No known key found for this signature in database
GPG Key ID: 93AC7B3D071356D3
2 changed files with 23 additions and 2 deletions

View File

@ -17,7 +17,7 @@ let soundAssetMap = {
// All available sounds
let soundAssets = {
debug_ding: new SoundSnippet("debug-ding")
debug_ding: new SoundSnippet("debug-ding", audioAssetType.sfx)
}
/**

View File

@ -2,13 +2,20 @@
// Counter for hash generation
let _hashCounter = 0;
// Audio types
let audioAssetType = {
bgm: 1,
sfx:2
}
class SoundSnippet {
/**
* Load a sound asset to a snipper
* @param {string} asset_name Asset name as defined in soundassetmap.js
* @param {*} asset_type Asset type. This changes the volume channel
*/
constructor(asset_name) {
constructor(asset_name, asset_type) {
// Store asset name
this.asset_name = asset_name;
@ -20,6 +27,8 @@ class SoundSnippet {
// Read actual asset path
this.assetPath = soundAssetMap[asset_name];
this.assetType = asset_type;
}
/**
@ -33,6 +42,18 @@ class SoundSnippet {
// Create a callback for loading finished
this.audio.once("load", callback);
// Configure a thread for updating the clip volume
setInterval(() => {
// Read the asset volume from the settings screen
let audio_volume = (this.assetType == 1)? volume.bgm :volume.sfx;
// Configure the clip volume
this.audio.volume(audio_volume);
}, 500);
}