import * as Phaser from "phaser"; /** * 安全播放音效。 * - 音效键不存在时静默返回 null(不抛异常) * - 可通过 config 控制音量、循环等 */ export function safePlaySound( scene: Phaser.Scene, key: string, config?: Phaser.Types.Sound.SoundConfig, ): Phaser.Sound.BaseSound | null { if (!scene.cache.audio.exists(key)) { return null; } try { return scene.sound.play(key, config) as unknown as Phaser.Sound.BaseSound; } catch { return null; } }