From 0e0ccd52fc7f67fc0ad2811f554559c860140277 Mon Sep 17 00:00:00 2001 From: donggang <> Date: Tue, 9 Jan 2024 16:55:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=98=BE=E7=A4=BA=E5=B1=82Ga?= =?UTF-8?q?meComponent=E6=A8=A1=E6=9D=BF=E6=94=AF=E6=8C=81=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E8=B5=84=E6=BA=90=E6=92=AD=E6=94=BEAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/module/common/GameComponent.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/assets/module/common/GameComponent.ts b/assets/module/common/GameComponent.ts index 7781c8f..81657a2 100644 --- a/assets/module/common/GameComponent.ts +++ b/assets/module/common/GameComponent.ts @@ -178,6 +178,26 @@ export class GameComponent extends Component { } //#endregion + //#region 音频播放管理 + /** + * 循环播放背景音乐 - 音频资源会在对象释放时自动释放 + * @param url 资源地址 + */ + playMusic(url: string) { + this.resPaths.set(url, oops.res.defaultBundleName); + oops.audio.playerMusicLoop(url); + } + + /** + * 播放音效 - 音频资源会在对象释放时自动释放 + * @param url 资源地址 + */ + playEffect(url: string) { + this.resPaths.set(url, oops.res.defaultBundleName); + oops.audio.playEffect(url); + } + //#endregion + protected onDestroy() { // 释放消息对象 if (this._event) {