Init and dispose audio player

This commit is contained in:
Eric Rosenbaum 2018-01-09 15:57:33 -05:00
parent 7c0117e9ed
commit 283804c21c
2 changed files with 11 additions and 8 deletions

View file

@ -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;
}
}
}
@ -942,6 +940,10 @@ class RenderedTarget extends Target {
this.runtime.requestRedraw();
}
}
if (this.audioPlayer) {
this.audioPlayer.stopAllSounds();
this.audioPlayer.dispose();
}
}
}

View file

@ -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);