mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -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
|
'control_start_as_clone', null, this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audio player
|
* Initialize the audio player for this sprite or clone.
|
||||||
*/
|
*/
|
||||||
|
initAudio () {
|
||||||
this.audioPlayer = null;
|
this.audioPlayer = null;
|
||||||
if (this.runtime && this.runtime.audioEngine) {
|
if (this.runtime && this.runtime.audioEngine) {
|
||||||
if (this.isOriginal) {
|
|
||||||
this.audioPlayer = this.runtime.audioEngine.createPlayer();
|
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();
|
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);
|
const newClone = new RenderedTarget(this, this.runtime);
|
||||||
newClone.isOriginal = this.clones.length === 0;
|
newClone.isOriginal = this.clones.length === 0;
|
||||||
this.clones.push(newClone);
|
this.clones.push(newClone);
|
||||||
|
newClone.initAudio();
|
||||||
if (newClone.isOriginal) {
|
if (newClone.isOriginal) {
|
||||||
newClone.initDrawable();
|
newClone.initDrawable();
|
||||||
this.runtime.fireTargetWasCreated(newClone);
|
this.runtime.fireTargetWasCreated(newClone);
|
||||||
|
|
Loading…
Reference in a new issue