diff options
| author | Gubolin <gubolin@fantasymail.de> | 2014-08-02 15:56:55 +0200 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2014-08-02 15:56:55 +0200 |
| commit | cc2f9bc84d5085e1380ceb3043d4ad5af3384b54 (patch) | |
| tree | d093ec807617be9d2dca22ce509fe15602fc77ed /objects.js | |
| parent | 2e00359fbb4b692dbbdc69a413b53ec9cd2579c6 (diff) | |
| download | snap-cc2f9bc84d5085e1380ceb3043d4ad5af3384b54.tar.gz snap-cc2f9bc84d5085e1380ceb3043d4ad5af3384b54.zip | |
volume blocks: user sprite's volume, apply previous changes to stage
Diffstat (limited to 'objects.js')
| -rw-r--r-- | objects.js | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -1313,6 +1313,8 @@ SpriteMorph.prototype.init = function (globals) { this.version = Date.now(); // for observer optimization this.isClone = false; // indicate a "temporary" Scratch-style clone this.cloneOriginName = ''; + this.volume = 100; + this.activeSounds = []; // sprite nesting properties this.parts = []; // not serialized, only anchor (name) @@ -2602,7 +2604,7 @@ SpriteMorph.prototype.reportCostumes = function () { // SpriteMorph sound management SpriteMorph.prototype.addSound = function (audio, name) { - var volume = this.parentThatIsA(StageMorph).volume; + var volume = this.volume; this.sounds.add(new Sound(audio, name, volume)); }; @@ -2614,8 +2616,14 @@ SpriteMorph.prototype.playSound = function (name) { ), active; if (sound) { - sound.volume = stage.volume; + sound.volume = this.volume; active = sound.play(); + + this.activeSounds.push(active); + this.activeSounds = this.activeSounds.filter(function (aud) { + return !aud.ended && !aud.terminated; + }); + if (stage) { stage.activeSounds.push(active); stage.activeSounds = stage.activeSounds.filter(function (aud) { @@ -2627,23 +2635,20 @@ SpriteMorph.prototype.playSound = function (name) { }; SpriteMorph.prototype.doSetVolume = function (val) { - var stage = this.parentThatIsA(StageMorph); - - stage.volume = Math.min(Math.max(0, val), 100); + var myself = this; - stage.activeSounds.forEach(function (snd) { - snd.volume = stage.volume / 100; // 'audio' objects + myself.volume = val; + myself.activeSounds.forEach(function (snd) { + snd.volume = Math.min(Math.max(0, myself.volume), 100) / 100; // 'audio' objects }); }; SpriteMorph.prototype.doChangeVolume = function (val) { - var stage = this.parentThatIsA(StageMorph); - this.doSetVolume(stage.volume + val); + this.doSetVolume(this.volume + val); }; SpriteMorph.prototype.reportVolume = function () { - var stage = this.parentThatIsA(StageMorph); - return stage.volume; + return this.volume; } SpriteMorph.prototype.reportSounds = function () { @@ -4929,7 +4934,10 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('playSound')); blocks.push(block('doPlaySoundUntilDone')); blocks.push(block('doStopAllSounds')); + blocks.push('-'); blocks.push(block('doSetVolume')); + blocks.push(block('doChangeVolume')); + blocks.push(watcherToggle('reportVolume')); blocks.push(block('reportVolume')); blocks.push('-'); blocks.push(block('doRest')); @@ -5474,6 +5482,9 @@ StageMorph.prototype.playSound StageMorph.prototype.doSetVolume = SpriteMorph.prototype.doSetVolume; +StageMorph.prototype.doChangeVolume + = SpriteMorph.prototype.doChangeVolume; + StageMorph.prototype.reportVolume = SpriteMorph.prototype.reportVolume; |
