mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Init and dispose audio player
This commit is contained in:
parent
7c0117e9ed
commit
283804c21c
2 changed files with 11 additions and 8 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue