A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix: resolve audio URLs with asset base URL in editor play mode
esengine0b494dc495a9
diff --git a/editor/src/services/PlayModeService.ts b/editor/src/services/PlayModeService.tsindex 7053c5607..f12dede02 100644--- a/editor/src/services/PlayModeService.ts+++ b/editor/src/services/PlayModeService.ts@@ -90,9 +90,9 @@ class PlayModeService {},fixedTimestep: getSettingsValue<number>('physics.fixedTimestep') ?? 1 / 60,subStepCount: getSettingsValue<number>('physics.subStepCount') ?? 4,- contactHertz: getSettingsValue<number>('physics.contactHertz') ?? 120,+ contactHertz: getSettingsValue<number>('physics.contactHertz') ?? 30,contactDampingRatio: getSettingsValue<number>('physics.contactDampingRatio') ?? 10,- contactSpeed: getSettingsValue<number>('physics.contactSpeed') ?? 10,+ contactSpeed: getSettingsValue<number>('physics.contactSpeed') ?? 3,collisionLayerMasks: Array.from({ length: MAX_COLLISION_LAYERS }, (_, i) =>getSettingsValue<number>(`physics.layerMask${i}`) ?? 0xFFFF),@@ -107,6 +107,7 @@ class PlayModeService {if (this.state_ !== 'playing') return;Audio.stopAll();+ Audio.baseUrl = '';audioPlugin.stopAllSources();this.cleanupSceneManager();@@ -252,7 +253,9 @@ class PlayModeService {if (!fs?.toAssetUrl) return;const assetServer = app.getResource(Assets);- assetServer.baseUrl = fs.toAssetUrl(projectDir);+ const assetBaseUrl = fs.toAssetUrl(projectDir);+ assetServer.baseUrl = assetBaseUrl;+ Audio.baseUrl = assetBaseUrl;const db = getAssetDatabase();assetServer.setAssetRefResolver((ref: string) => {diff --git a/sdk/src/audio/Audio.ts b/sdk/src/audio/Audio.tsindex 8165f1432..b8e0c4a1f 100644--- a/sdk/src/audio/Audio.ts+++ b/sdk/src/audio/Audio.ts@@ -9,6 +9,7 @@ export class Audio {private static bgmVolume_ = 1.0;private static fadeAnimId_ = 0;private static disposed_ = false;+ static baseUrl = '';static init(backend: PlatformAudioBackend, mixer: AudioMixer | null = null): void {this.backend_ = backend;@@ -23,9 +24,16 @@ export class Audio {}}+ private static resolveUrl_(url: string): string {+ if (!this.baseUrl || url.startsWith('/') || url.startsWith('http://') || url.startsWith('https://')) {+ return url;+ }+ return `${this.baseUrl}/${url}`;+ }+static async preload(url: string): Promise<void> {if (this.bufferCache_.has(url)) return;- const buffer = await this.backend_.loadBuffer(url);+ const buffer = await this.backend_.loadBuffer(this.resolveUrl_(url));this.bufferCache_.set(url, buffer);}