Skip to content

Commit d0fa50f

Browse files
committed
Fixed issue stopping SoundManager.volume from working correctly on a global volume basis (fix # 488)
1 parent 4a97861 commit d0fa50f

3 files changed

Lines changed: 73 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ Bug Fixes:
168168
* Fixed TilemapParser - would spit out a tileset warning if margin/spacing were set (fix #485, thanks Cybolic)
169169
* AnimationParser.spriteSheet wasn't taking the margin or spacing into account when calculating the numbers of sprites per row/column, nor was it allowing for extra power-of-two padding at the end (fix #482, thanks yig)
170170
* AnimationManager.add documentation said that 'frames' could be null, but the code couldn't handle this so it defaults to an empty array if none given (thanks yig)
171+
* Fixed issue stopping SoundManager.volume from working correctly on a global volume basis (fix # 488)
171172

172173

173174
TO DO:

examples/wip/focus mute.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png');
7+
8+
// Firefox doesn't support mp3 files, so use ogg
9+
game.load.audio('boden', ['assets/audio/bodenstaendig_2000_in_rock_4bit.mp3', 'assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']);
10+
11+
}
12+
13+
var s;
14+
var music;
15+
16+
function create() {
17+
18+
game.stage.backgroundColor = '#182d3b';
19+
game.input.touch.preventDefault = false;
20+
21+
music = game.add.audio('boden');
22+
music.play();
23+
24+
s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk');
25+
s.anchor.setTo(0.5, 0.5);
26+
27+
game.input.onDown.add(changeVolume, this);
28+
29+
}
30+
31+
function changeVolume(pointer) {
32+
33+
if (pointer.y < 300)
34+
{
35+
game.sound.volume += 0.1;
36+
// music.volume += 0.1;
37+
}
38+
else
39+
{
40+
game.sound.volume -= 0.1;
41+
// music.volume -= 0.1;
42+
}
43+
44+
}
45+
46+
function update() {
47+
s.rotation += 0.01;
48+
}
49+
50+
function render() {
51+
game.debug.renderSoundInfo(music, 20, 32);
52+
}
53+

src/sound/SoundManager.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ Phaser.SoundManager.prototype = {
371371

372372
},
373373

374+
/**
375+
* Internal mute handler called automatically by the Sound.mute setter.
376+
*
377+
* @method Phaser.SoundManager#setMute
378+
* @private
379+
*/
374380
setMute: function () {
375381

376382
if (this._muted)
@@ -397,6 +403,12 @@ Phaser.SoundManager.prototype = {
397403

398404
},
399405

406+
/**
407+
* Internal mute handler called automatically by the Sound.mute setter.
408+
*
409+
* @method Phaser.SoundManager#unsetMute
410+
* @private
411+
*/
400412
unsetMute: function () {
401413

402414
if (!this._muted || this._codeMuted)
@@ -487,21 +499,21 @@ Object.defineProperty(Phaser.SoundManager.prototype, "volume", {
487499

488500
set: function (value) {
489501

490-
value = this.game.math.clamp(value, 1, 0);
491-
492502
this._volume = value;
493503

494504
if (this.usingWebAudio)
495505
{
496506
this.masterGain.gain.value = value;
497507
}
498-
499-
// Loop through the sound cache and change the volume of all html audio tags
500-
for (var i = 0; i < this._sounds.length; i++)
508+
else
501509
{
502-
if (this._sounds[i].usingAudioTag)
510+
// Loop through the sound cache and change the volume of all html audio tags
511+
for (var i = 0; i < this._sounds.length; i++)
503512
{
504-
this._sounds[i].volume = this._sounds[i].volume * value;
513+
if (this._sounds[i].usingAudioTag)
514+
{
515+
this._sounds[i].volume = this._sounds[i].volume * value;
516+
}
505517
}
506518
}
507519

0 commit comments

Comments
 (0)