mirror of
https://github.com/wassname/phaser.git
synced 2026-07-13 01:00:12 +08:00
Pausing the game will now mute audio and resuming will un-mute, unless it was muted via the game (fixes #439)
This commit is contained in:
@@ -132,6 +132,7 @@ Updates:
|
||||
* Updated the way the page visibility is checked, should now be more compatible across more browsers.
|
||||
* Phaser.Input.Key.isUp now defaults to 'true', as does GamepadButton.isUp (#474)
|
||||
* Vastly improved visibility API support + pageshow/pagehide + focus/blur. Working across Chrome, IE, Firefox, iOS, Android (also fixes #161)
|
||||
* Pausing the game will now mute audio and resuming will un-mute, unless it was muted via the game (fixes #439)
|
||||
|
||||
|
||||
Bug Fixes:
|
||||
@@ -152,6 +153,7 @@ Bug Fixes:
|
||||
* Text that was fixedToCamera would 'jitter' if the world scrolled. Now works as expected across all fixed objects.
|
||||
* Fixed a bug where Sound.play wouldn't pick-up the local loop setting if not specified in the parameter.
|
||||
* Active animations now monitor if the game pauses, and resume normally when the game un-pauses (fixes #179)
|
||||
* Swapping between tabs will now pause the game correctly on mobile browsers (iOS7+)
|
||||
|
||||
|
||||
TO DO:
|
||||
|
||||
@@ -31,12 +31,25 @@ function create() {
|
||||
game.onResume.add(resumed, this);
|
||||
|
||||
var space = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
|
||||
space.onDown.add(pauseToggle, this);
|
||||
space.onDown.add(muteToggle, this);
|
||||
|
||||
s.push('starting: ' + game.stage._hiddenVar);
|
||||
|
||||
}
|
||||
|
||||
function muteToggle() {
|
||||
|
||||
if (game.sound.mute)
|
||||
{
|
||||
game.sound.mute = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
game.sound.mute = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function pauseToggle() {
|
||||
|
||||
if (game.paused)
|
||||
|
||||
+2
-2
@@ -736,7 +736,7 @@ Phaser.Game.prototype = {
|
||||
{
|
||||
this._paused = true;
|
||||
this.time.gamePaused(time);
|
||||
this.sound.mute = true;
|
||||
this.sound.setMute();
|
||||
this.onPause.dispatch(this);
|
||||
}
|
||||
|
||||
@@ -755,7 +755,7 @@ Phaser.Game.prototype = {
|
||||
this._paused = false;
|
||||
this.time.gameResumed(time);
|
||||
this.input.reset();
|
||||
this.sound.mute = false;
|
||||
this.sound.unsetMute();
|
||||
this.onResume.dispatch(this);
|
||||
}
|
||||
|
||||
|
||||
+62
-31
@@ -26,6 +26,13 @@ Phaser.SoundManager = function (game) {
|
||||
*/
|
||||
this.onSoundDecode = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {boolean} _codeMuted - Internal mute tracking var.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._codeMuted = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} _muted - Internal mute tracking var.
|
||||
* @private
|
||||
@@ -362,6 +369,57 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
return sound;
|
||||
|
||||
},
|
||||
|
||||
setMute: function () {
|
||||
|
||||
if (this._muted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._muted = true;
|
||||
|
||||
if (this.usingWebAudio)
|
||||
{
|
||||
this._muteVolume = this.masterGain.gain.value;
|
||||
this.masterGain.gain.value = 0;
|
||||
}
|
||||
|
||||
// Loop through sounds
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
{
|
||||
if (this._sounds[i].usingAudioTag)
|
||||
{
|
||||
this._sounds[i].mute = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
unsetMute: function () {
|
||||
|
||||
if (!this._muted || this._codeMuted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._muted = false;
|
||||
|
||||
if (this.usingWebAudio)
|
||||
{
|
||||
this.masterGain.gain.value = this._muteVolume;
|
||||
}
|
||||
|
||||
// Loop through sounds
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
{
|
||||
if (this._sounds[i].usingAudioTag)
|
||||
{
|
||||
this._sounds[i].mute = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -391,22 +449,8 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
return;
|
||||
}
|
||||
|
||||
this._muted = true;
|
||||
|
||||
if (this.usingWebAudio)
|
||||
{
|
||||
this._muteVolume = this.masterGain.gain.value;
|
||||
this.masterGain.gain.value = 0;
|
||||
}
|
||||
|
||||
// Loop through sounds
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
{
|
||||
if (this._sounds[i].usingAudioTag)
|
||||
{
|
||||
this._sounds[i].mute = true;
|
||||
}
|
||||
}
|
||||
this._codeMuted = true;
|
||||
this.setMute();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -415,21 +459,8 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
return;
|
||||
}
|
||||
|
||||
this._muted = false;
|
||||
|
||||
if (this.usingWebAudio)
|
||||
{
|
||||
this.masterGain.gain.value = this._muteVolume;
|
||||
}
|
||||
|
||||
// Loop through sounds
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
{
|
||||
if (this._sounds[i].usingAudioTag)
|
||||
{
|
||||
this._sounds[i].mute = false;
|
||||
}
|
||||
}
|
||||
this._codeMuted = false;
|
||||
this.unsetMute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user