mirror of
https://github.com/wassname/phaser.git
synced 2026-08-16 11:25:21 +08:00
JSDocs update ;)
This commit is contained in:
+107
-13
@@ -3,26 +3,70 @@
|
||||
*
|
||||
* @class Sound
|
||||
* @constructor
|
||||
* @param game {Phaser.Game} reference to the current game instance.
|
||||
* @param key {string} Asset key for the sound.
|
||||
* @param volume {number} default value for the volume.
|
||||
* @param loop {bool} Whether or not the sound will loop.
|
||||
* @param {Phaser.Game} game Reference to the current game instance.
|
||||
* @param {string} key Asset key for the sound.
|
||||
* @param {number} volume Default value for the volume.
|
||||
* @param {bool} loop Whether or not the sound will loop.
|
||||
*/
|
||||
Phaser.Sound = function (game, key, volume, loop) {
|
||||
|
||||
volume = volume || 1;
|
||||
if (typeof loop == 'undefined') { loop = false; }
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Name of the sound
|
||||
* @property name
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* Asset key for the sound.
|
||||
* @property key
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* Whether or not the sound will loop.
|
||||
* @property loop
|
||||
* @public
|
||||
* @type {bool}
|
||||
*/
|
||||
this.loop = loop;
|
||||
|
||||
/**
|
||||
* The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
* @property _volume
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this._volume = volume;
|
||||
|
||||
/**
|
||||
* The sound markers, empty by default
|
||||
* @property markers
|
||||
* @public
|
||||
* @type {object}
|
||||
*/
|
||||
this.markers = {};
|
||||
|
||||
|
||||
/**
|
||||
* Reference to AudioContext instance.
|
||||
* @property context
|
||||
* @public
|
||||
* @type {AudioContext}
|
||||
*/
|
||||
this.context = null;
|
||||
|
||||
@@ -31,9 +75,28 @@ Phaser.Sound = function (game, key, volume, loop) {
|
||||
*/
|
||||
this._buffer = null;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the game is on "mute"
|
||||
* @property _muted
|
||||
* @private
|
||||
* @type {bool}
|
||||
*/
|
||||
this._muted = false;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the sound should start automatically
|
||||
* @property autoplay
|
||||
* @public
|
||||
* @type {bool}
|
||||
*/
|
||||
this.autoplay = false;
|
||||
|
||||
/**
|
||||
* The total duration of the sound, in milliseconds
|
||||
* @property autoplay
|
||||
* @public
|
||||
* @type {bool}
|
||||
*/
|
||||
this.totalDuration = 0;
|
||||
this.startTime = 0;
|
||||
this.currentTime = 0;
|
||||
@@ -188,11 +251,11 @@ Phaser.Sound.prototype = {
|
||||
|
||||
/**
|
||||
* Play this sound, or a marked section of it.
|
||||
|
||||
* @param marker {string} Assets key of the sound you want to play.
|
||||
* @param position {number} the starting position
|
||||
* @param [volume] {number} volume of the sound you want to play.
|
||||
* @param [loop] {bool} loop when it finished playing? (Default to false)
|
||||
* @method play
|
||||
* @param {string} marker Assets key of the sound you want to play.
|
||||
* @param {number} position The starting position
|
||||
* @param {number} [volume] Volume of the sound you want to play.
|
||||
* @param {bool} [loop] Loop when it finished playing? (Default to false)
|
||||
* @return {Sound} The playing sound object.
|
||||
*/
|
||||
play: function (marker, position, volume, loop, forceRestart) {
|
||||
@@ -366,6 +429,14 @@ Phaser.Sound.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Restart the sound, or a marked section of it.
|
||||
* @method restart
|
||||
* @param {string} marker Assets key of the sound you want to play.
|
||||
* @param {number} position The starting position
|
||||
* @param {number} [volume] Volume of the sound you want to play.
|
||||
* @param {bool} [loop] Loop when it finished playing? (Default to false)
|
||||
*/
|
||||
restart: function (marker, position, volume, loop) {
|
||||
|
||||
marker = marker || '';
|
||||
@@ -377,6 +448,10 @@ Phaser.Sound.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Pauses the sound
|
||||
* @method pause
|
||||
*/
|
||||
pause: function () {
|
||||
|
||||
if (this.isPlaying && this._sound)
|
||||
@@ -388,7 +463,10 @@ Phaser.Sound.prototype = {
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resumes the sound
|
||||
* @method pause
|
||||
*/
|
||||
resume: function () {
|
||||
|
||||
if (this.paused && this._sound)
|
||||
@@ -419,6 +497,7 @@ Phaser.Sound.prototype = {
|
||||
|
||||
/**
|
||||
* Stop playing this sound.
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
@@ -470,13 +549,20 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", {
|
||||
|
||||
Object.defineProperty(Phaser.Sound.prototype, "mute", {
|
||||
|
||||
/**
|
||||
* Mute sounds.
|
||||
|
||||
/**
|
||||
* Mutes sound.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the sound is muted
|
||||
*/
|
||||
get: function () {
|
||||
return this._muted;
|
||||
},
|
||||
|
||||
/**
|
||||
* Mutes sound.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the sound is muted
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
value = value || null;
|
||||
@@ -518,10 +604,18 @@ Object.defineProperty(Phaser.Sound.prototype, "mute", {
|
||||
|
||||
Object.defineProperty(Phaser.Sound.prototype, "volume", {
|
||||
|
||||
/**
|
||||
* @method volume
|
||||
* @return {number} The current volume. A value between 0 (silence) and 1 (full volume)
|
||||
*/
|
||||
get: function () {
|
||||
return this._volume;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method volume
|
||||
* @return {number} Sets the current volume. A value between 0 (silence) and 1 (full volume)
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
if (this.usingWebAudio)
|
||||
|
||||
+73
-11
@@ -3,20 +3,47 @@
|
||||
*
|
||||
* @class SoundManager
|
||||
* @constructor
|
||||
* @param game {Phaser.Game} reference to the current game instance.
|
||||
* @param {Phaser.Game} game reference to the current game instance.
|
||||
*/
|
||||
Phaser.SoundManager = function (game) {
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
this.onSoundDecode = new Phaser.Signal;
|
||||
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the game is on "mute"
|
||||
* @property _muted
|
||||
* @private
|
||||
* @type {bool}
|
||||
*/
|
||||
this._muted = false;
|
||||
this._unlockSource = null;
|
||||
|
||||
/**
|
||||
* The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
* @property _volume
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this._volume = 1;
|
||||
this._muted = false;
|
||||
|
||||
/**
|
||||
* An array containing all the sounds
|
||||
* @property _sounds
|
||||
* @private
|
||||
* @type {array}
|
||||
*/
|
||||
this._sounds = [];
|
||||
|
||||
|
||||
this.context = null;
|
||||
this.usingWebAudio = true;
|
||||
this.usingAudioTag = false;
|
||||
@@ -30,6 +57,10 @@ Phaser.SoundManager = function (game) {
|
||||
|
||||
Phaser.SoundManager.prototype = {
|
||||
|
||||
/**
|
||||
* Initialises the sound manager
|
||||
* @method boot
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
if (this.game.device.iOS && this.game.device.webAudio == false)
|
||||
@@ -108,6 +139,10 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Enables the audio, usually after the first touch
|
||||
* @method unlock
|
||||
*/
|
||||
unlock: function () {
|
||||
|
||||
if (this.touchLocked == false)
|
||||
@@ -138,6 +173,10 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops all the sounds in the game
|
||||
* @method stopAll
|
||||
*/
|
||||
stopAll: function () {
|
||||
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
@@ -150,6 +189,10 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Pauses all the sounds in the game
|
||||
* @method pauseAll
|
||||
*/
|
||||
pauseAll: function () {
|
||||
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
@@ -162,6 +205,10 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* resumes every sound in the game
|
||||
* @method resumeAll
|
||||
*/
|
||||
resumeAll: function () {
|
||||
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
@@ -176,8 +223,9 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
/**
|
||||
* Decode a sound with its assets key.
|
||||
* @method decode
|
||||
* @param key {string} Assets key of the sound to be decoded.
|
||||
* @param [sound] {Sound} its bufer will be set to decoded data.
|
||||
* @param [sound] {Phaser.Sound} its bufer will be set to decoded data.
|
||||
*/
|
||||
decode: function (key, sound) {
|
||||
|
||||
@@ -205,6 +253,10 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* updates every sound in the game
|
||||
* @method update
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.touchLocked)
|
||||
@@ -232,11 +284,10 @@ Phaser.SoundManager.prototype = {
|
||||
/**
|
||||
*
|
||||
* @method add
|
||||
* @param key {string} Asset key for the sound.
|
||||
* @param volume {number} default value for the volume.
|
||||
* @param loop {bool} Whether or not the sound will loop.
|
||||
* @param {string} key Asset key for the sound.
|
||||
* @param {number} volume Default value for the volume.
|
||||
* @param {bool} loop Whether or not the sound will loop.
|
||||
*/
|
||||
|
||||
add: function (key, volume, loop) {
|
||||
|
||||
volume = volume || 1;
|
||||
@@ -258,6 +309,8 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
|
||||
/**
|
||||
* A global audio mute toggle.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the game is on "mute"
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
@@ -265,6 +318,11 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Mute sounds.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the game is on "mute"
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
value = value || null;
|
||||
@@ -316,14 +374,16 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.SoundManager.prototype, "volume", {
|
||||
|
||||
/**
|
||||
* @method volume
|
||||
* @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
if (this.usingWebAudio)
|
||||
@@ -338,7 +398,9 @@ Object.defineProperty(Phaser.SoundManager.prototype, "volume", {
|
||||
},
|
||||
|
||||
/**
|
||||
* The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
* Sets the global volume
|
||||
* @method volume
|
||||
* @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user