From 283804c21c859564da1ddc3870746dc65d8e1522 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 9 Jan 2018 15:57:33 -0500 Subject: [PATCH] Init and dispose audio player --- src/sprites/rendered-target.js | 18 ++++++++++-------- src/sprites/sprite.js | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 1288240da..4a1e7cddb 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -131,17 +131,15 @@ class RenderedTarget extends Target { 'control_start_as_clone', null, this ); } + } - /** - * Audio player - */ + /** + * Initialize the audio player for this sprite or clone. + */ + initAudio () { this.audioPlayer = null; if (this.runtime && this.runtime.audioEngine) { - if (this.isOriginal) { - this.audioPlayer = this.runtime.audioEngine.createPlayer(); - } else { - this.audioPlayer = this.sprite.clones[0].audioPlayer; - } + this.audioPlayer = this.runtime.audioEngine.createPlayer(); } } @@ -942,6 +940,10 @@ class RenderedTarget extends Target { this.runtime.requestRedraw(); } } + if (this.audioPlayer) { + this.audioPlayer.stopAllSounds(); + this.audioPlayer.dispose(); + } } } diff --git a/src/sprites/sprite.js b/src/sprites/sprite.js index 268184343..bf68c98d1 100644 --- a/src/sprites/sprite.js +++ b/src/sprites/sprite.js @@ -56,6 +56,7 @@ class Sprite { const newClone = new RenderedTarget(this, this.runtime); newClone.isOriginal = this.clones.length === 0; this.clones.push(newClone); + newClone.initAudio(); if (newClone.isOriginal) { newClone.initDrawable(); this.runtime.fireTargetWasCreated(newClone);