summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-08-02 12:08:56 +0200
committerGubolin <gubolin@fantasymail.de>2014-08-02 12:08:56 +0200
commit2e00359fbb4b692dbbdc69a413b53ec9cd2579c6 (patch)
treeb912fb21ec0ef3af40b7d4a71d7d62e8c4a84338
parentc8d27ee26adffdae1a11dec64b0cf00a5c8b7b9d (diff)
downloadsnap-2e00359fbb4b692dbbdc69a413b53ec9cd2579c6.tar.gz
snap-2e00359fbb4b692dbbdc69a413b53ec9cd2579c6.zip
add block to change volume
-rw-r--r--objects.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/objects.js b/objects.js
index 65d483d..c898cd9 100644
--- a/objects.js
+++ b/objects.js
@@ -465,6 +465,12 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'set volume to %n %',
defaults: [100]
},
+ doChangeVolume: {
+ type: 'command',
+ category: 'sound',
+ spec: 'change volume by %n',
+ defaults: [-10]
+ },
reportVolume: {
type: 'reporter',
category: 'sound',
@@ -1767,6 +1773,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('doStopAllSounds'));
blocks.push('-');
blocks.push(block('doSetVolume'));
+ blocks.push(block('doChangeVolume'));
blocks.push(watcherToggle('reportVolume'));
blocks.push(block('reportVolume'));
blocks.push('-');
@@ -2622,13 +2629,18 @@ SpriteMorph.prototype.playSound = function (name) {
SpriteMorph.prototype.doSetVolume = function (val) {
var stage = this.parentThatIsA(StageMorph);
- stage.volume = val;
+ stage.volume = Math.min(Math.max(0, val), 100);
stage.activeSounds.forEach(function (snd) {
- snd.volume = Math.min(Math.max(0, stage.volume), 100) / 100; // 'audio' objects
+ snd.volume = stage.volume / 100; // 'audio' objects
});
};
+SpriteMorph.prototype.doChangeVolume = function (val) {
+ var stage = this.parentThatIsA(StageMorph);
+ this.doSetVolume(stage.volume + val);
+};
+
SpriteMorph.prototype.reportVolume = function () {
var stage = this.parentThatIsA(StageMorph);
return stage.volume;