pause and continue all audio

beta.r3js.org
-=yb4f310 2017-11-21 15:35:57 +01:00
parent 2c7d0625cc
commit 61400ed6c2
4 changed files with 100 additions and 26 deletions

26
build/game-lib-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
// COMPILE TIME DEFINITIONS (Generated via gulp)
var __DATE__ = "Tue Nov 21 2017 15:07:22 GMT+0100 (CET)";
var __DATE__ = "Tue Nov 21 2017 15:24:50 GMT+0100 (CET)";
// END COMPILE TIME DEFINITIONS
/**
@ -177,6 +177,8 @@ GameLib.Event.MOUSE_WHEEL = 0x5f;
GameLib.Event.MOUSE_UP = 0x60;
GameLib.Event.PARTICLE_INSTANCE_UPDATED = 0x61;
GameLib.Event.GAME_DATA = 0x62;
GameLib.Event.PAUSE_ALL_AUDIO = 0x63;
GameLib.Event.CONTINUE_ALL_AUDIO = 0x64;
/**
* Returns string name of event ID
@ -285,6 +287,8 @@ GameLib.Event.GetEventName = function(number) {
case 0x60 : return 'mouse_up';
case 0x61 : return 'particle_instance_updated';
case 0x62 : return 'game_data';
case 0x63 : return 'pause_all_audio';
case 0x64 : return 'continue_all_audio';
break;
}
@ -25544,12 +25548,18 @@ GameLib.System.Audio = function(
this.playAudioSubscription = null;
this.pauseAudioSubscription = null;
this.pauseAllAudioSubscription = null;
this.continueAllAudioSubscription = null;
this.stopAudioSubscription = null;
this.stopAllAudioSubscription = null;
this.mute = false;
this.paused = [];
this.audioComponents = [];
this.toPlay = [];
@ -25580,9 +25590,15 @@ GameLib.System.Audio.prototype.start = function() {
this.playAudio.bind(this)
);
this.pauseAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.PAUSE_AUDIO,
this.pauseAudio.bind(this)
this.pauseAllAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.PAUSE_ALL_AUDIO,
this.pauseAllAudio.bind(this)
);
this.continueAllAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.CONTINUE_ALL_AUDIO,
this.continueAllAudio.bind(this)
);
this.stopAudioSubscription = GameLib.Event.Subscribe(
@ -25669,7 +25685,27 @@ GameLib.System.Audio.prototype.playAudio = function(data) {
}
};
GameLib.System.Audio.prototype.pauseAudio = function(data) {
GameLib.System.Audio.prototype.pauseAllAudio = function(data) {
this.paused = [];
this.audioComponents.map(
function(audio) {
if (audio.instance.isPlaying) {
audio.instance.pause();
this.paused.push(audio);
}
}.bind(this)
)
};
GameLib.System.Audio.prototype.continueAllAudio = function(data) {
this.paused.map(
function(audio) {
audio.instance.play();
}
);
};
@ -25712,7 +25748,8 @@ GameLib.System.Audio.prototype.stop = function() {
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
this.playAudioSubscription.remove();
this.pauseAudioSubscription.remove();
this.pauseAllAudioSubscription.remove();
this.continueAllAudioSubscription.remove();
this.stopAudioSubscription.remove();
this.stopAllAudioSubscription.remove();

View File

@ -113,6 +113,8 @@ GameLib.Event.MOUSE_WHEEL = 0x5f;
GameLib.Event.MOUSE_UP = 0x60;
GameLib.Event.PARTICLE_INSTANCE_UPDATED = 0x61;
GameLib.Event.GAME_DATA = 0x62;
GameLib.Event.PAUSE_ALL_AUDIO = 0x63;
GameLib.Event.CONTINUE_ALL_AUDIO = 0x64;
/**
* Returns string name of event ID
@ -221,6 +223,8 @@ GameLib.Event.GetEventName = function(number) {
case 0x60 : return 'mouse_up';
case 0x61 : return 'particle_instance_updated';
case 0x62 : return 'game_data';
case 0x63 : return 'pause_all_audio';
case 0x64 : return 'continue_all_audio';
break;
}

View File

@ -17,12 +17,18 @@ GameLib.System.Audio = function(
this.playAudioSubscription = null;
this.pauseAudioSubscription = null;
this.pauseAllAudioSubscription = null;
this.continueAllAudioSubscription = null;
this.stopAudioSubscription = null;
this.stopAllAudioSubscription = null;
this.mute = false;
this.paused = [];
this.audioComponents = [];
this.toPlay = [];
@ -53,9 +59,15 @@ GameLib.System.Audio.prototype.start = function() {
this.playAudio.bind(this)
);
this.pauseAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.PAUSE_AUDIO,
this.pauseAudio.bind(this)
this.pauseAllAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.PAUSE_ALL_AUDIO,
this.pauseAllAudio.bind(this)
);
this.continueAllAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.CONTINUE_ALL_AUDIO,
this.continueAllAudio.bind(this)
);
this.stopAudioSubscription = GameLib.Event.Subscribe(
@ -142,7 +154,27 @@ GameLib.System.Audio.prototype.playAudio = function(data) {
}
};
GameLib.System.Audio.prototype.pauseAudio = function(data) {
GameLib.System.Audio.prototype.pauseAllAudio = function(data) {
this.paused = [];
this.audioComponents.map(
function(audio) {
if (audio.instance.isPlaying) {
audio.instance.pause();
this.paused.push(audio);
}
}.bind(this)
)
};
GameLib.System.Audio.prototype.continueAllAudio = function(data) {
this.paused.map(
function(audio) {
audio.instance.play();
}
);
};
@ -185,7 +217,8 @@ GameLib.System.Audio.prototype.stop = function() {
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
this.playAudioSubscription.remove();
this.pauseAudioSubscription.remove();
this.pauseAllAudioSubscription.remove();
this.continueAllAudioSubscription.remove();
this.stopAudioSubscription.remove();
this.stopAllAudioSubscription.remove();