From b561ce41ee0d8fe79ea824fe12c464957a78aa20 Mon Sep 17 00:00:00 2001 From: Gokul Rajiv Date: Sun, 1 Aug 2021 22:17:59 +0800 Subject: [PATCH 1/2] sound and anims fixes --- src/features/game/animations/GameAnimationManager.ts | 6 ++++-- src/features/game/sound/GameSoundManager.ts | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/features/game/animations/GameAnimationManager.ts b/src/features/game/animations/GameAnimationManager.ts index 45a670cb9b..91a2d17a62 100644 --- a/src/features/game/animations/GameAnimationManager.ts +++ b/src/features/game/animations/GameAnimationManager.ts @@ -67,7 +67,7 @@ export default class GameAnimationManager { GameGlobalAPI.getInstance().addItem(GameItemType.objects, currLoc, image.key); break; case AnimType.Background: - GameGlobalAPI.getInstance().renderBackgroundLayerContainer(image.path); + GameGlobalAPI.getInstance().renderBackgroundLayerContainer(image.key); break; } } @@ -114,7 +114,9 @@ export default class GameAnimationManager { */ public startAnimation(image: ImageAsset) { if (this.isSprite(image)) { - this.getAnimation(image).play(image.path); + const sprite = this.getAnimation(image); + sprite.play(image.path, false); + this.game.add.existing(sprite); } } diff --git a/src/features/game/sound/GameSoundManager.ts b/src/features/game/sound/GameSoundManager.ts index 3e6c6e0c2f..1d92579d40 100644 --- a/src/features/game/sound/GameSoundManager.ts +++ b/src/features/game/sound/GameSoundManager.ts @@ -187,7 +187,13 @@ class GameSoundManager { duration: fadeDuration }); - setTimeout(() => sound.destroy(), fadeDuration * 2); + const befScene = this.getCurrentScene().scene.key; + setTimeout(() => { + const aftScene = this.getCurrentScene().scene.key; + if (this.getBaseSoundManager().game && befScene === aftScene) { + sound.destroy(); + } + }, fadeDuration * 2); } /** From 61816f26d14bdf2ed0f002d1911f66a6584b1b3a Mon Sep 17 00:00:00 2001 From: Gokul Rajiv Date: Mon, 2 Aug 2021 23:43:06 +0800 Subject: [PATCH 2/2] Replace hacky fix with a TODO --- src/features/game/sound/GameSoundManager.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/features/game/sound/GameSoundManager.ts b/src/features/game/sound/GameSoundManager.ts index 1d92579d40..894aa81b69 100644 --- a/src/features/game/sound/GameSoundManager.ts +++ b/src/features/game/sound/GameSoundManager.ts @@ -187,13 +187,9 @@ class GameSoundManager { duration: fadeDuration }); - const befScene = this.getCurrentScene().scene.key; - setTimeout(() => { - const aftScene = this.getCurrentScene().scene.key; - if (this.getBaseSoundManager().game && befScene === aftScene) { - sound.destroy(); - } - }, fadeDuration * 2); + // TODO: fix `TypeError: Cannot read property 'disconnect' of null` error + // when user navigates away from game scene before fadeDuration * 2 + setTimeout(() => sound.destroy(), fadeDuration * 2); } /**