Add volume control to audio clips
This commit is contained in:
parent
44944626ef
commit
f11bdb4892
@ -17,7 +17,7 @@ let soundAssetMap = {
|
|||||||
|
|
||||||
// All available sounds
|
// All available sounds
|
||||||
let soundAssets = {
|
let soundAssets = {
|
||||||
debug_ding: new SoundSnippet("debug-ding")
|
debug_ding: new SoundSnippet("debug-ding", audioAssetType.sfx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,13 +2,20 @@
|
|||||||
// Counter for hash generation
|
// Counter for hash generation
|
||||||
let _hashCounter = 0;
|
let _hashCounter = 0;
|
||||||
|
|
||||||
|
// Audio types
|
||||||
|
let audioAssetType = {
|
||||||
|
bgm: 1,
|
||||||
|
sfx:2
|
||||||
|
}
|
||||||
|
|
||||||
class SoundSnippet {
|
class SoundSnippet {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a sound asset to a snipper
|
* Load a sound asset to a snipper
|
||||||
* @param {string} asset_name Asset name as defined in soundassetmap.js
|
* @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
|
// Store asset name
|
||||||
this.asset_name = asset_name;
|
this.asset_name = asset_name;
|
||||||
@ -20,6 +27,8 @@ class SoundSnippet {
|
|||||||
// Read actual asset path
|
// Read actual asset path
|
||||||
this.assetPath = soundAssetMap[asset_name];
|
this.assetPath = soundAssetMap[asset_name];
|
||||||
|
|
||||||
|
this.assetType = asset_type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,6 +42,18 @@ class SoundSnippet {
|
|||||||
|
|
||||||
// Create a callback for loading finished
|
// Create a callback for loading finished
|
||||||
this.audio.once("load", callback);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user