mirror of
https://github.com/wassname/phaser.git
synced 2026-09-11 12:31:29 +08:00
Adding docs.
This commit is contained in:
+195
-72
@@ -1,12 +1,21 @@
|
||||
|
||||
/**
|
||||
* The Sound class
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Sound
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Sound class constructor.
|
||||
*
|
||||
* @class Sound
|
||||
* @class Phaser.Sound
|
||||
* @classdesc The Sound class
|
||||
* @constructor
|
||||
* @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.
|
||||
* @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) {
|
||||
|
||||
@@ -15,101 +24,152 @@ Phaser.Sound = function (game, key, volume, loop) {
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
* @property {Phaser.Game} game
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Name of the sound
|
||||
* @property name
|
||||
* @public
|
||||
* @type {string}
|
||||
* Name of the sound.
|
||||
* @property {string} name
|
||||
* @default
|
||||
*/
|
||||
this.name = key;
|
||||
|
||||
/**
|
||||
* Asset key for the sound.
|
||||
* @property key
|
||||
* @public
|
||||
* @type {string}
|
||||
* @property {string} key
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* Whether or not the sound will loop.
|
||||
* @property loop
|
||||
* @public
|
||||
* @type {bool}
|
||||
* @property {bool} loop
|
||||
*/
|
||||
this.loop = loop;
|
||||
|
||||
/**
|
||||
* The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
* @property _volume
|
||||
* The global audio volume. A value between 0 (silence) and 1 (full volume).
|
||||
* @property {number} _volume
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this._volume = volume;
|
||||
|
||||
/**
|
||||
* The sound markers, empty by default
|
||||
* @property markers
|
||||
* @public
|
||||
* @type {object}
|
||||
* The sound markers, empty by default.
|
||||
* @property {object} markers
|
||||
*/
|
||||
this.markers = {};
|
||||
|
||||
|
||||
/**
|
||||
* Reference to AudioContext instance.
|
||||
* @property context
|
||||
* @public
|
||||
* @type {AudioContext}
|
||||
* @property {AudioContext} context
|
||||
* @default
|
||||
*/
|
||||
this.context = null;
|
||||
|
||||
/**
|
||||
* Decoded data buffer / Audio tag.
|
||||
* @property {Description} _buffer
|
||||
* @private
|
||||
*/
|
||||
this._buffer = null;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the game is on "mute"
|
||||
* @property _muted
|
||||
* Boolean indicating whether the game is on "mute".
|
||||
* @property {bool} _muted
|
||||
* @private
|
||||
* @type {bool}
|
||||
* @default
|
||||
*/
|
||||
this._muted = false;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the sound should start automatically
|
||||
* @property autoplay
|
||||
* @public
|
||||
* @type {bool}
|
||||
* Boolean indicating whether the sound should start automatically.
|
||||
* @property {bool} autoplay
|
||||
* @private
|
||||
*/
|
||||
this.autoplay = false;
|
||||
|
||||
/**
|
||||
* The total duration of the sound, in milliseconds
|
||||
* @property autoplay
|
||||
* @public
|
||||
* @type {bool}
|
||||
* @property {number} totalDuration
|
||||
* @default
|
||||
*/
|
||||
this.totalDuration = 0;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {number} startTime
|
||||
* @default
|
||||
*/
|
||||
this.startTime = 0;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {number} currentTime
|
||||
* @default
|
||||
*/
|
||||
this.currentTime = 0;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {number} duration
|
||||
* @default
|
||||
*/
|
||||
this.duration = 0;
|
||||
this.durationMS = 0;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {number} autoplay
|
||||
* @default
|
||||
*/
|
||||
this.stopTime = 0;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {bool} paused
|
||||
* @default
|
||||
*/
|
||||
this.paused = false;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {bool} isPlaying
|
||||
* @default
|
||||
*/
|
||||
this.isPlaying = false;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {string} currentMarker
|
||||
* @default
|
||||
*/
|
||||
this.currentMarker = '';
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {bool} pendingPlayback
|
||||
* @default
|
||||
*/
|
||||
this.pendingPlayback = false;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {bool} override
|
||||
* @default
|
||||
*/
|
||||
this.override = false;
|
||||
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {bool} usingWebAudio
|
||||
*/
|
||||
this.usingWebAudio = this.game.sound.usingWebAudio;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} usingAudioTag
|
||||
*/
|
||||
this.usingAudioTag = this.game.sound.usingAudioTag;
|
||||
|
||||
if (this.usingWebAudio)
|
||||
@@ -147,19 +207,62 @@ Phaser.Sound = function (game, key, volume, loop) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onDecoded
|
||||
*/
|
||||
this.onDecoded = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onPlay
|
||||
*/
|
||||
this.onPlay = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onPause
|
||||
*/
|
||||
this.onPause = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onResume
|
||||
*/
|
||||
this.onResume = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onLoop
|
||||
*/
|
||||
this.onLoop = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onStop
|
||||
*/
|
||||
this.onStop = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onMute
|
||||
*/
|
||||
this.onMute = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Phaser.Signal} onMarkerComplete
|
||||
*/
|
||||
this.onMarkerComplete = new Phaser.Signal;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Sound.prototype = {
|
||||
|
||||
/**
|
||||
* @method soundHasUnlocked
|
||||
* @param {string} key - Description.
|
||||
*/
|
||||
soundHasUnlocked: function (key) {
|
||||
|
||||
if (key == this.key)
|
||||
@@ -171,9 +274,15 @@ Phaser.Sound.prototype = {
|
||||
|
||||
},
|
||||
|
||||
// start and stop are in SECONDS.MS (2.5 = 2500ms, 0.5 = 500ms, etc)
|
||||
// volume is between 0 and 1
|
||||
/*
|
||||
/**
|
||||
* Description.
|
||||
* @method addMarker
|
||||
* @param {string} name - Description.
|
||||
* @param {Description} start - Description.
|
||||
* @param {Description} stop - Description.
|
||||
* @param {Description} volume - Description.
|
||||
* @param {Description} loop - Description.
|
||||
*/
|
||||
addMarker: function (name, start, stop, volume, loop) {
|
||||
|
||||
volume = volume || 1;
|
||||
@@ -210,12 +319,21 @@ Phaser.Sound.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method removeMarker
|
||||
* @param {string} name - Description.
|
||||
*/
|
||||
removeMarker: function (name) {
|
||||
|
||||
delete this.markers[name];
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method update
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.pendingPlayback && this.game.cache.isSoundReady(this.key))
|
||||
@@ -276,10 +394,11 @@ Phaser.Sound.prototype = {
|
||||
/**
|
||||
* Play this sound, or a marked section of it.
|
||||
* @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)
|
||||
* @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)
|
||||
* @param {Description} forceRestart - Description.
|
||||
* @return {Sound} The playing sound object.
|
||||
*/
|
||||
play: function (marker, position, volume, loop, forceRestart) {
|
||||
@@ -472,10 +591,10 @@ 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)
|
||||
* @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) {
|
||||
|
||||
@@ -505,7 +624,7 @@ Phaser.Sound.prototype = {
|
||||
},
|
||||
/**
|
||||
* Resumes the sound
|
||||
* @method pause
|
||||
* @method resume
|
||||
*/
|
||||
resume: function () {
|
||||
|
||||
@@ -571,6 +690,10 @@ Phaser.Sound.prototype = {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {bool} Description.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sound.prototype, "isDecoding", {
|
||||
|
||||
get: function () {
|
||||
@@ -579,6 +702,10 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoding", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {bool} Description.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sound.prototype, "isDecoded", {
|
||||
|
||||
get: function () {
|
||||
@@ -587,22 +714,19 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {bool} Whether or not the sound is muted.
|
||||
*//**
|
||||
* Mutes sound.
|
||||
* @param {bool} value - Whether or not the sound is muted.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sound.prototype, "mute", {
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
@@ -642,20 +766,19 @@ Object.defineProperty(Phaser.Sound.prototype, "mute", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the current volume. A value between 0 (silence) and 1 (full volume).
|
||||
* @return {number}
|
||||
*//**
|
||||
* Set
|
||||
* @param {number} value - Sets the current volume. A value between 0 (silence) and 1 (full volume).
|
||||
*/
|
||||
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)
|
||||
|
||||
+89
-55
@@ -1,56 +1,93 @@
|
||||
/**
|
||||
* Phaser - SoundManager
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.SoundManager
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Sound Manager constructor.
|
||||
*
|
||||
* @class SoundManager
|
||||
* @class Phaser.SoundManager
|
||||
* @classdesc Phaser Sound Manager.
|
||||
* @constructor
|
||||
* @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}
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onSoundDecode - Description.
|
||||
*/
|
||||
this.onSoundDecode = new Phaser.Signal;
|
||||
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the game is on "mute"
|
||||
* @property _muted
|
||||
* @private
|
||||
* @type {bool}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @property {bool} _muted - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._muted = false;
|
||||
|
||||
/**
|
||||
* @property {Description} _unlockSource - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._unlockSource = null;
|
||||
|
||||
/**
|
||||
* The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
* @property _volume
|
||||
* @property {number} _volume - The global audio volume. A value between 0 (silence) and 1 (full volume).
|
||||
* @private
|
||||
* @type {number}
|
||||
* @default
|
||||
*/
|
||||
this._volume = 1;
|
||||
|
||||
/**
|
||||
* An array containing all the sounds
|
||||
* @property _sounds
|
||||
* @property {array} _sounds - An array containing all the sounds
|
||||
* @private
|
||||
* @type {array}
|
||||
* @default The empty array.
|
||||
*/
|
||||
this._sounds = [];
|
||||
|
||||
|
||||
/**
|
||||
* @property {Description} context - Description.
|
||||
* @default
|
||||
*/
|
||||
this.context = null;
|
||||
|
||||
/**
|
||||
* @property {bool} usingWebAudio - Description.
|
||||
* @default
|
||||
*/
|
||||
this.usingWebAudio = true;
|
||||
|
||||
/**
|
||||
* @property {bool} usingAudioTag - Description.
|
||||
* @default
|
||||
*/
|
||||
this.usingAudioTag = false;
|
||||
|
||||
/**
|
||||
* @property {bool} noAudio - Description.
|
||||
* @default
|
||||
*/
|
||||
this.noAudio = false;
|
||||
|
||||
/**
|
||||
* @property {bool} touchLocked - Description.
|
||||
* @default
|
||||
*/
|
||||
this.touchLocked = false;
|
||||
|
||||
/**
|
||||
* @property {number} channels - Description.
|
||||
* @default
|
||||
*/
|
||||
this.channels = 32;
|
||||
|
||||
};
|
||||
@@ -58,7 +95,7 @@ Phaser.SoundManager = function (game) {
|
||||
Phaser.SoundManager.prototype = {
|
||||
|
||||
/**
|
||||
* Initialises the sound manager
|
||||
* Initialises the sound manager.
|
||||
* @method boot
|
||||
*/
|
||||
boot: function () {
|
||||
@@ -140,7 +177,7 @@ Phaser.SoundManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Enables the audio, usually after the first touch
|
||||
* Enables the audio, usually after the first touch.
|
||||
* @method unlock
|
||||
*/
|
||||
unlock: function () {
|
||||
@@ -174,7 +211,7 @@ Phaser.SoundManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops all the sounds in the game
|
||||
* Stops all the sounds in the game.
|
||||
* @method stopAll
|
||||
*/
|
||||
stopAll: function () {
|
||||
@@ -190,7 +227,7 @@ Phaser.SoundManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Pauses all the sounds in the game
|
||||
* Pauses all the sounds in the game.
|
||||
* @method pauseAll
|
||||
*/
|
||||
pauseAll: function () {
|
||||
@@ -206,7 +243,7 @@ Phaser.SoundManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* resumes every sound in the game
|
||||
* resumes every sound in the game.
|
||||
* @method resumeAll
|
||||
*/
|
||||
resumeAll: function () {
|
||||
@@ -224,8 +261,8 @@ 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] {Phaser.Sound} its bufer will be set to decoded data.
|
||||
* @param {string} key - Assets key of the sound to be decoded.
|
||||
* @param {Phaser.Sound} [sound] - Its buffer will be set to decoded data.
|
||||
*/
|
||||
decode: function (key, sound) {
|
||||
|
||||
@@ -254,7 +291,7 @@ Phaser.SoundManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* updates every sound in the game
|
||||
* Updates every sound in the game.
|
||||
* @method update
|
||||
*/
|
||||
update: function () {
|
||||
@@ -282,17 +319,19 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Description.
|
||||
* @method add
|
||||
* @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.
|
||||
* @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;
|
||||
if (typeof loop == 'undefined') { loop = false; }
|
||||
|
||||
|
||||
|
||||
var sound = new Phaser.Sound(this.game, key, volume, loop);
|
||||
|
||||
this._sounds.push(sound);
|
||||
@@ -303,24 +342,21 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* A global audio mute toggle.
|
||||
* @return {bool} Whether or not the game is on "mute".
|
||||
*//**
|
||||
* Mute sounds.
|
||||
* @param {bool} value - Whether or not the game is on "mute"
|
||||
*/
|
||||
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 () {
|
||||
|
||||
return this._muted;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Mute sounds.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the game is on "mute"
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
value = value || null;
|
||||
@@ -376,12 +412,15 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume).
|
||||
*//**
|
||||
* Sets the global volume
|
||||
* @return {number} value - The global audio volume. A value between 0 (silence) and 1 (full volume).
|
||||
*/
|
||||
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)
|
||||
@@ -395,11 +434,6 @@ Object.defineProperty(Phaser.SoundManager.prototype, "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) {
|
||||
|
||||
value = this.game.math.clamp(value, 1, 0);
|
||||
|
||||
Reference in New Issue
Block a user