Updated documentation.

This commit is contained in:
photonstorm
2013-11-28 15:57:09 +00:00
parent 8da9b67c18
commit f22159e257
193 changed files with 68905 additions and 93104 deletions
+163 -140
View File
@@ -54,6 +54,10 @@
<a href="Phaser.AnimationParser.html">AnimationParser</a>
</li>
<li>
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
<li>
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
@@ -138,6 +142,10 @@
<a href="Phaser.Events.html">Events</a>
</li>
<li>
<a href="Phaser.Filter.html">Filter</a>
</li>
<li>
<a href="Phaser.Frame.html">Frame</a>
</li>
@@ -302,6 +310,26 @@
<a href="Phaser.Text.html">Text</a>
</li>
<li>
<a href="Phaser.Tile.html">Tile</a>
</li>
<li>
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
<li>
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
<li>
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
<li>
<a href="Phaser.Tileset.html">Tileset</a>
</li>
<li>
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
@@ -310,6 +338,10 @@
<a href="Phaser.Time.html">Time</a>
</li>
<li>
<a href="Phaser.Timer.html">Timer</a>
</li>
<li>
<a href="Phaser.Touch.html">Touch</a>
</li>
@@ -356,6 +388,14 @@
<a href="global.html#HEXtoRGB">HEXtoRGB</a>
</li>
<li>
<a href="global.html#render">render</a>
</li>
<li>
<a href="global.html#renderXY">renderXY</a>
</li>
<li>
<a href="global.html#right">right</a>
</li>
@@ -398,10 +438,11 @@
* @param {number} [volume=1] - Default value for the volume, between 0 and 1.
* @param {boolean} [loop=false] - Whether or not the sound will loop.
*/
Phaser.Sound = function (game, key, volume, loop) {
volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; }
Phaser.Sound = function (game, key, volume, loop, connect) {
if (typeof volume == 'undefined') { volume = 1; }
if (typeof loop == 'undefined') { loop = false; }
if (typeof connect === 'undefined') { connect = game.sound.connectToMaster; }
/**
* A reference to the currently running Game.
@@ -410,160 +451,136 @@ Phaser.Sound = function (game, key, volume, loop) {
this.game = game;
/**
* Name of the sound.
* @property {string} name
* @default
* @property {string} name - Name of the sound.
*/
this.name = key;
/**
* Asset key for the sound.
* @property {string} key
* @property {string} key - Asset key for the sound.
*/
this.key = key;
/**
* Whether or not the sound will loop.
* @property {boolean} loop
* @property {boolean} loop - Whether or not the sound will loop.
*/
this.loop = loop;
/**
* The global audio volume. A value between 0 (silence) and 1 (full volume).
* @property {number} _volume
* @property {number} _volume - The global audio volume. A value between 0 (silence) and 1 (full volume).
* @private
*/
this._volume = volume;
/**
* The sound markers, empty by default.
* @property {object} markers
* @property {object} markers - The sound markers.
*/
this.markers = {};
/**
* Reference to AudioContext instance.
* @property {AudioContext} context
* @default
* @property {AudioContext} context - Reference to the AudioContext instance.
*/
this.context = null;
/**
* Decoded data buffer / Audio tag.
* @property {Description} _buffer
* @property {Description} _buffer - Decoded data buffer / Audio tag.
* @private
*/
this._buffer = null;
/**
* Boolean indicating whether the game is on "mute".
* @property {boolean} _muted
* @property {boolean} _muted - Boolean indicating whether the sound is muted or not.
* @private
* @default
*/
this._muted = false;
/**
* Boolean indicating whether the sound should start automatically.
* @property {boolean} autoplay
* @private
* @property {boolean} autoplay - Boolean indicating whether the sound should start automatically.
*/
this.autoplay = false;
/**
* The total duration of the sound, in milliseconds
* @property {number} totalDuration
* @default
* @property {number} totalDuration - The total duration of the sound, in milliseconds
*/
this.totalDuration = 0;
/**
* Description.
* @property {number} startTime
* @property {number} startTime - The time the Sound starts at (typically 0 unless starting from a marker)
* @default
*/
this.startTime = 0;
/**
* Description.
* @property {number} currentTime
* @default
* @property {number} currentTime - The current time the sound is at.
*/
this.currentTime = 0;
/**
* Description.
* @property {number} duration
* @default
* @property {number} duration - The duration of the sound.
*/
this.duration = 0;
/**
* Description.
* @property {number} stopTime
* @property {number} stopTime - The time the sound stopped.
*/
this.stopTime = 0;
/**
* Description.
* @property {boolean} paused
* @property {boolean} paused - true if the sound is paused, otherwise false.
* @default
*/
this.paused = false;
/**
* Description.
* @property {number} pausedPosition
* @property {number} pausedPosition - The position the sound had reached when it was paused.
*/
this.pausedPosition = 0;
/**
* Description.
* @property {number} pausedTime
* @property {number} pausedTime - The game time at which the sound was paused.
*/
this.pausedTime = 0;
/**
* Description.
* @property {boolean} isPlaying
* @property {boolean} isPlaying - true if the sound is currently playing, otherwise false.
* @default
*/
this.isPlaying = false;
/**
* Description.
* @property {string} currentMarker
* @property {string} currentMarker - The string ID of the currently playing marker, if any.
* @default
*/
this.currentMarker = '';
/**
* Description.
* @property {boolean} pendingPlayback
* @default
* @property {boolean} pendingPlayback - true if the sound file is pending playback
* @readonly
*/
this.pendingPlayback = false;
/**
* Description.
* @property {boolean} override
* @property {boolean} override - if true when you play this sound it will always start from the beginning.
* @default
*/
this.override = false;
/**
* Description.
* @property {boolean} usingWebAudio
* @property {boolean} usingWebAudio - true if this sound is being played with Web Audio.
* @readonly
*/
this.usingWebAudio = this.game.sound.usingWebAudio;
/**
* Description.
* @property {Description} usingAudioTag
* @property {boolean} usingAudioTag - true if the sound is being played via the Audio tag.
*/
this.usingAudioTag = this.game.sound.usingAudioTag;
/**
* @property {object} externalNode - If defined this Sound won't connect to the SoundManager master gain node, but will instead connect to externalNode.input.
*/
this.externalNode = null;
if (this.usingWebAudio)
{
this.context = this.game.sound.context;
@@ -579,7 +596,11 @@ Phaser.Sound = function (game, key, volume, loop) {
}
this.gainNode.gain.value = volume * this.game.sound.volume;
this.gainNode.connect(this.masterGainNode);
if (connect)
{
this.gainNode.connect(this.masterGainNode);
}
}
else
{
@@ -600,63 +621,55 @@ Phaser.Sound = function (game, key, volume, loop) {
}
/**
* Description.
* @property {Phaser.Signal} onDecoded
* @property {Phaser.Signal} onDecoded - The onDecoded event is dispatched when the sound has finished decoding (typically for mp3 files)
*/
this.onDecoded = new Phaser.Signal;
this.onDecoded = new Phaser.Signal();
/**
* Description.
* @property {Phaser.Signal} onPlay
* @property {Phaser.Signal} onPlay - The onPlay event is dispatched each time this sound is played.
*/
this.onPlay = new Phaser.Signal;
this.onPlay = new Phaser.Signal();
/**
* Description.
* @property {Phaser.Signal} onPause
* @property {Phaser.Signal} onPause - The onPause event is dispatched when this sound is paused.
*/
this.onPause = new Phaser.Signal;
this.onPause = new Phaser.Signal();
/**
* Description.
* @property {Phaser.Signal} onResume
* @property {Phaser.Signal} onResume - The onResume event is dispatched when this sound is resumed from a paused state.
*/
this.onResume = new Phaser.Signal;
this.onResume = new Phaser.Signal();
/**
* Description.
* @property {Phaser.Signal} onLoop
* @property {Phaser.Signal} onLoop - The onLoop event is dispatched when this sound loops during playback.
*/
this.onLoop = new Phaser.Signal;
this.onLoop = new Phaser.Signal();
/**
* Description.
* @property {Phaser.Signal} onStop
* @property {Phaser.Signal} onStop - The onStop event is dispatched when this sound stops playback.
*/
this.onStop = new Phaser.Signal;
this.onStop = new Phaser.Signal();
/**
* Description.
* @property {Phaser.Signal} onMute
* @property {Phaser.Signal} onMute - The onMouse event is dispatched when this sound is muted.
*/
this.onMute = new Phaser.Signal;
this.onMute = new Phaser.Signal();
/**
* Description.
* @property {Phaser.Signal} onMarkerComplete
* @property {Phaser.Signal} onMarkerComplete - The onMarkerComplete event is dispatched when a marker within this sound completes playback.
*/
this.onMarkerComplete = new Phaser.Signal;
this.onMarkerComplete = new Phaser.Signal();
};
Phaser.Sound.prototype = {
/**
/**
* Called automatically when this sound is unlocked.
* @method Phaser.Sound#soundHasUnlocked
* @param {string} key - Description.
* @method Phaser.Sound#soundHasUnlocked
* @param {string} key - The Phaser.Cache key of the sound file to check for decoding.
* @protected
*/
*/
soundHasUnlocked: function (key) {
if (key == this.key)
@@ -664,22 +677,22 @@ Phaser.Sound.prototype = {
this._sound = this.game.cache.getSoundData(this.key);
this.totalDuration = this._sound.duration;
// console.log('sound has unlocked' + this._sound);
}
}
},
},
/**
* Description.
* @method Phaser.Sound#addMarker
* @param {string} name - Description.
* @param {Description} start - Description.
* @param {Description} stop - Description.
* @param {Description} volume - Description.
* @param {Description} loop - Description.
/**
* Description.
* @method Phaser.Sound#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;
if (typeof loop == 'undefined') { loop = false; }
volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; }
this.markers[name] = {
name: name,
@@ -721,22 +734,22 @@ Phaser.Sound.prototype = {
},
/**
* Removes a marker from the sound.
* @method Phaser.Sound#removeMarker
* @param {string} name - The key of the marker to remove.
*/
/**
* Removes a marker from the sound.
* @method Phaser.Sound#removeMarker
* @param {string} name - The key of the marker to remove.
*/
removeMarker: function (name) {
delete this.markers[name];
},
/**
* Called automatically by Phaser.SoundManager.
* @method Phaser.Sound#update
/**
* Called automatically by Phaser.SoundManager.
* @method Phaser.Sound#update
* @protected
*/
*/
update: function () {
if (this.pendingPlayback && this.game.cache.isSoundReady(this.key))
@@ -760,7 +773,7 @@ Phaser.Sound.prototype = {
// won't work with markers, needs to reset the position
this.onLoop.dispatch(this);
if (this.currentMarker == '')
if (this.currentMarker === '')
{
//console.log('loop2');
this.currentTime = 0;
@@ -794,27 +807,28 @@ Phaser.Sound.prototype = {
}
},
/**
/**
* Play this sound, or a marked section of it.
* @method Phaser.Sound#play
* @param {string} [marker=''] - If you want to play a marker then give the key here, otherwise leave blank to play the full sound.
* @param {number} [position=0] - The starting position to play the sound from - this is ignored if you provide a marker.
* @param {number} [volume=1] - Volume of the sound you want to play.
* @param {number} [volume=1] - Volume of the sound you want to play. If none is given it will use the volume given to the Sound when it was created (which defaults to 1 if none was specified).
* @param {boolean} [loop=false] - Loop when it finished playing?
* @param {boolean} [forceRestart=true] - If the sound is already playing you can set forceRestart to restart it from the beginning.
* @return {Sound} The playing sound object.
* @return {Phaser.Sound} This sound instance.
*/
play: function (marker, position, volume, loop, forceRestart) {
marker = marker || '';
position = position || 0;
volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; }
if (typeof forceRestart == 'undefined') { forceRestart = true; }
marker = marker || '';
position = position || 0;
if (typeof volume === 'undefined') { volume = this._volume; }
if (typeof loop === 'undefined') { loop = false; }
if (typeof forceRestart === 'undefined') { forceRestart = true; }
// console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart);
if (this.isPlaying == true && forceRestart == false && this.override == false)
if (this.isPlaying === true && forceRestart === false && this.override === false)
{
// Use Restart instead
return;
@@ -896,17 +910,26 @@ Phaser.Sound.prototype = {
this._sound = this.context.createBufferSource();
this._sound.buffer = this._buffer;
this._sound.connect(this.gainNode);
if (this.externalNode)
{
this._sound.connect(this.externalNode.input);
}
else
{
this._sound.connect(this.gainNode);
}
this.totalDuration = this._sound.buffer.duration;
if (this.duration == 0)
if (this.duration === 0)
{
// console.log('duration reset');
this.duration = this.totalDuration;
this.durationMS = this.totalDuration * 1000;
}
if (this.loop && marker == '')
if (this.loop && marker === '')
{
this._sound.loop = true;
}
@@ -917,9 +940,9 @@ Phaser.Sound.prototype = {
this._sound.noteGrainOn(0, this.position, this.duration);
// this._sound.noteGrainOn(0, this.position, this.duration / 1000);
//this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
}
else
{
}
else
{
// this._sound.start(0, this.position, this.duration / 1000);
this._sound.start(0, this.position, this.duration);
}
@@ -929,12 +952,12 @@ Phaser.Sound.prototype = {
this.currentTime = 0;
this.stopTime = this.startTime + this.durationMS;
this.onPlay.dispatch(this);
}
else
{
}
else
{
this.pendingPlayback = true;
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false)
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding === false)
{
this.game.sound.decode(this.key, this);
}
@@ -958,7 +981,7 @@ Phaser.Sound.prototype = {
// This doesn't become available until you call play(), wonderful ...
this.totalDuration = this._sound.duration;
if (this.duration == 0)
if (this.duration === 0)
{
this.duration = this.totalDuration;
this.durationMS = this.totalDuration * 1000;
@@ -1001,10 +1024,10 @@ Phaser.Sound.prototype = {
*/
restart: function (marker, position, volume, loop) {
marker = marker || '';
position = position || 0;
volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; }
marker = marker || '';
position = position || 0;
volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; }
this.play(marker, position, volume, loop, true);
@@ -1048,9 +1071,9 @@ Phaser.Sound.prototype = {
{
this._sound.noteGrainOn(0, p, this.duration);
//this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
}
else
{
}
else
{
this._sound.start(0, p, this.duration);
}
}
@@ -1067,7 +1090,7 @@ Phaser.Sound.prototype = {
},
/**
/**
* Stop playing this sound.
* @method Phaser.Sound#stop
*/
@@ -1134,14 +1157,14 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", {
* @property {boolean} mute - Gets or sets the muted state of this sound.
*/
Object.defineProperty(Phaser.Sound.prototype, "mute", {
get: function () {
return this._muted;
},
set: function (value) {
value = value || null;
value = value || null;
if (value)
{
@@ -1229,7 +1252,7 @@ Object.defineProperty(Phaser.Sound.prototype, "volume", {
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
on Thu Nov 07 2013 06:07:33 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Thu Nov 28 2013 15:56:25 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>