LayaAir 没有单独封装 oscillator API。Web 端可以直接使用浏览器的 Web Audio API,例如点击舞台后播放 1 秒的 440Hz 正弦波:
await Laya.init(800, 600);
const AC = window.AudioContext || (window as any).webkitAudioContext;
const ctx = new AC();
Laya.stage.once("click", null, async () => {
await ctx.resume();
const oscillator = ctx.createOscillator();
const gain = ctx.createGain();
oscillator.type = "sine";
oscillator.frequency.value = 440;
gain.gain.value = 0.1;
oscillator.connect(gain);
gain.connect(ctx.destination);
oscillator.start();
oscillator.stop(ctx.currentTime + 1);
});
小游戏或 Native 平台需要使用对应平台提供的音频能力。
以上由 AI(codex)自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。