diff --git a/core/block_svg.js b/core/block_svg.js index 745d58b65..2ae02fc5c 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -982,6 +982,7 @@ Blockly.BlockSvg.prototype.getSvgRoot = function() { * @param {boolean} animate If true, show a disposal animation and sound. */ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { + Blockly.Tooltip.hide(); Blockly.Field.startCache(); // If this block is being dragged, unlink the mouse events. if (Blockly.selected == this) { diff --git a/core/constants.js b/core/constants.js index 27de6cea6..f082905d5 100644 --- a/core/constants.js +++ b/core/constants.js @@ -52,6 +52,12 @@ Blockly.COLLAPSE_CHARS = 30; */ Blockly.LONGPRESS = 750; +/** + * Prevent a sound from playing if another sound preceded it within this many + * miliseconds. + */ +Blockly.SOUND_LIMIT = 100; + /** * The richness of block colours, regardless of the hue. * Must be in the range of 0 (inclusive) to 1 (exclusive). diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 69ab56d92..8e7db32ea 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -131,6 +131,13 @@ Blockly.WorkspaceSvg.prototype.trashcan = null; */ Blockly.WorkspaceSvg.prototype.scrollbar = null; +/** + * Time that the last sound was played. + * @type {Date} + * @private + */ +Blockly.WorkspaceSvg.prototype.lastSound_ = null; + /** * Create the workspace DOM elements. * @param {string=} opt_backgroundClass Either 'blocklyMainBackground' or @@ -904,6 +911,12 @@ Blockly.WorkspaceSvg.prototype.preloadAudio_ = function() { Blockly.WorkspaceSvg.prototype.playAudio = function(name, opt_volume) { var sound = this.SOUNDS_[name]; if (sound) { + // Don't play one sound on top of another. + var now = new Date(); + if (now - this.lastSound_ < Blockly.Blockly.SOUND_LIMIT) { + return; + } + this.lastSound_ = now; var mySound; var ie9 = goog.userAgent.DOCUMENT_MODE && goog.userAgent.DOCUMENT_MODE === 9;