功能:4种全屏特效增加 Web Audio API 实时合成音效
新建 public/js/effects/effect-sounds.js: - 雷电:低频白噪声爆裂 + 雷鸣渐衰(10次,与视觉同步) - 烟花:发射滑音(200→700Hz)+ 带通噪声爆炸(9轮) - 下雨:双层带通白噪声(1200Hz+3500Hz)持续淡入淡出 - 下雪:4000Hz+高频风声 + 五声音阶轻柔铃音(5次随机) - 所有音效纯 Web Audio API 合成,无外部音频文件 - 旧 AudioContext 若被 suspended 自动 resume effect-manager.js: - play() 调用 EffectSounds.play(type) 同步触发音效 - _cleanup() 调用 EffectSounds.stop() 兜底停止 frame.blade.php:effect-sounds.js 在 effect-manager 前引入
This commit is contained in:
@@ -38,7 +38,7 @@ const EffectManager = (() => {
|
||||
}
|
||||
|
||||
/**
|
||||
* 特效结束后清理 Canvas,重置状态
|
||||
* 特效结束后清理 Canvas,重置状态,并停止音效
|
||||
*/
|
||||
function _cleanup() {
|
||||
if (_canvas && document.body.contains(_canvas)) {
|
||||
@@ -46,6 +46,10 @@ const EffectManager = (() => {
|
||||
}
|
||||
_canvas = null;
|
||||
_current = null;
|
||||
// 通知音效引擎停止(兜底:正常情况下音效会自行计时结束)
|
||||
if (typeof EffectSounds !== "undefined") {
|
||||
EffectSounds.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,6 +69,11 @@ const EffectManager = (() => {
|
||||
const canvas = _getCanvas();
|
||||
_current = type;
|
||||
|
||||
// 同步触发对应音效
|
||||
if (typeof EffectSounds !== "undefined") {
|
||||
EffectSounds.play(type);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case "fireworks":
|
||||
if (typeof FireworksEffect !== "undefined") {
|
||||
|
||||
Reference in New Issue
Block a user