More Docs!

This commit is contained in:
Richard Davey
2013-10-03 01:21:08 +01:00
parent e85643abf4
commit f832bacfd6
102 changed files with 26598 additions and 1400 deletions
+22 -12
View File
@@ -2,20 +2,20 @@
* @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.Canvas
*/
/**
* The Canvas class handles everything related to the &lt;canvas&gt; tag as a DOM Element, like styles, offset, aspect ratio
*
* @class Canvas
* @class Phaser.Canvas
* @static
*/
Phaser.Canvas = {
/**
* Creates the &lt;canvas&gt; tag
*
* @method create
* @method Phaser.Canvas.create
* @param {number} width - The desired width.
* @param {number} height - The desired height.
* @return {HTMLCanvasElement} The newly created &lt;canvas&gt; tag.
@@ -35,7 +35,7 @@ Phaser.Canvas = {
/**
* Get the DOM offset values of any given element
* @method getOffset
* @method Phaser.Canvas.getOffset
* @param {HTMLElement} element - The targeted element that we want to retrieve the offset.
* @param {Phaser.Point} [point] - The point we want to take the x/y values of the offset.
* @return {Phaser.Point} - A point objet with the offsetX and Y as its properties.
@@ -60,7 +60,7 @@ Phaser.Canvas = {
/**
* Returns the aspect ratio of the given canvas.
*
* @method getAspectRatio
* @method Phaser.Canvas.getAspectRatio
* @param {HTMLCanvasElement} canvas - The canvas to get the aspect ratio from.
* @return {number} The ratio between canvas' width and height.
*/
@@ -71,7 +71,7 @@ Phaser.Canvas = {
/**
* Sets the background color behind the canvas. This changes the canvas style property.
*
* @method setBackgroundColor
* @method Phaser.Canvas.setBackgroundColor
* @param {HTMLCanvasElement} canvas - The canvas to set the background color on.
* @param {string} [color] - The color to set. Can be in the format 'rgb(r,g,b)', or '#RRGGBB' or any valid CSS color.
* @return {HTMLCanvasElement} Returns the source canvas.
@@ -89,7 +89,7 @@ Phaser.Canvas = {
/**
* Sets the touch-action property on the canvas style. Can be used to disable default browser touch actions.
*
* @method setTouchAction
* @method Phaser.Canvas.setTouchAction
* @param {HTMLCanvasElement} canvas - The canvas to set the touch action on.
* @param {String} [value] - The touch action to set. Defaults to 'none'.
* @return {HTMLCanvasElement} The source canvas.
@@ -106,8 +106,18 @@ Phaser.Canvas = {
},
/**
* Sets the user-select property on the canvas style. Can be used to disable default browser selection actions.
*
* @method Phaser.Canvas.setUserSelect
* @param {HTMLCanvasElement} canvas - The canvas to set the touch action on.
* @param {String} [value] - The touch action to set. Defaults to 'none'.
* @return {HTMLCanvasElement} The source canvas.
*/
setUserSelect: function (canvas, value) {
value = value || 'none';
canvas.style['-webkit-touch-callout'] = value;
canvas.style['-webkit-user-select'] = value;
canvas.style['-khtml-user-select'] = value;
@@ -124,7 +134,7 @@ Phaser.Canvas = {
* Adds the given canvas element to the DOM. The canvas will be added as a child of the given parent.
* If no parent is given it will be added as a child of the document.body.
*
* @method addToDOM
* @method Phaser.Canvas.addToDOM
* @param {HTMLCanvasElement} canvas - The canvas to set the touch action on.
* @param {string} parent - The DOM element to add the canvas to. Defaults to ''.
* @param {boolean} overflowHidden - If set to true it will add the overflow='hidden' style to the parent DOM element.
@@ -164,7 +174,7 @@ Phaser.Canvas = {
/**
* Sets the transform of the given canvas to the matrix values provided.
*
* @method setTransform
* @method Phaser.Canvas.setTransform
* @param {CanvasRenderingContext2D} context - The context to set the transform on.
* @param {number} translateX - The value to translate horizontally by.
* @param {number} translateY - The value to translate vertically by.
@@ -189,7 +199,7 @@ Phaser.Canvas = {
* drawn to the context will be affected. This sets the property across all current browsers but support is
* patchy on earlier browsers, especially on mobile.
*
* @method setSmoothingEnabled
* @method Phaser.Canvas.setSmoothingEnabled
* @param {CanvasRenderingContext2D} context - The context to enable or disable the image smoothing on.
* @param {boolean} value - If set to true it will enable image smoothing, false will disable it.
* @return {CanvasRenderingContext2D} Returns the source context.
@@ -210,7 +220,7 @@ Phaser.Canvas = {
* Sets the CSS image-rendering property on the given canvas to be 'crisp' (aka 'optimize contrast on webkit').
* Note that if this doesn't given the desired result then see the setSmoothingEnabled.
*
* @method setImageRenderingCrisp
* @method Phaser.Canvas.setImageRenderingCrisp
* @param {HTMLCanvasElement} canvas - The canvas to set image-rendering crisp on.
* @return {HTMLCanvasElement} Returns the source canvas.
*/
@@ -229,7 +239,7 @@ Phaser.Canvas = {
* Sets the CSS image-rendering property on the given canvas to be 'bicubic' (aka 'auto').
* Note that if this doesn't given the desired result then see the CanvasUtils.setSmoothingEnabled method.
*
* @method setImageRenderingBicubic
* @method Phaser.Canvas.setImageRenderingBicubic
* @param {HTMLCanvasElement} canvas The canvas to set image-rendering bicubic on.
* @return {HTMLCanvasElement} Returns the source canvas.
*/
+34 -23
View File
@@ -2,13 +2,10 @@
* @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.Device
*/
/**
* Detects device support capabilities. Using some elements from System.js by MrDoob and Modernizr
* {@link https://github.com/Modernizr/Modernizr/blob/master/feature-detects/audio.js}
*
* @class Phaser.Device
* @constructor
@@ -17,8 +14,7 @@
Phaser.Device = function () {
/**
* An optional 'fix' for the horrendous Android stock browser bug
* {@link https://code.google.com/p/android/issues/detail?id=39247}
* An optional 'fix' for the horrendous Android stock browser bug https://code.google.com/p/android/issues/detail?id=39247
* @property {boolean} patchAndroidClearRectBug - Description.
* @default
*/
@@ -283,7 +279,7 @@ Phaser.Device.prototype = {
/**
* Check which OS is game running on.
* @method _checkOS
* @method Phaser.Device#_checkOS
* @private
*/
_checkOS: function () {
@@ -312,7 +308,7 @@ Phaser.Device.prototype = {
/**
* Check HTML5 features of the host environment.
* @method _checkFeatures
* @method Phaser.Device#_checkFeatures
* @private
*/
_checkFeatures: function () {
@@ -345,7 +341,7 @@ Phaser.Device.prototype = {
/**
* Check what browser is game running in.
* @method _checkBrowser
* @method Phaser.Device#_checkBrowser
* @private
*/
_checkBrowser: function () {
@@ -382,7 +378,7 @@ Phaser.Device.prototype = {
/**
* Check audio support.
* @method _checkAudio
* @method Phaser.Device#_checkAudio
* @private
*/
_checkAudio: function () {
@@ -429,7 +425,7 @@ Phaser.Device.prototype = {
/**
* Check PixelRatio of devices.
* @method _checkDevice
* @method Phaser.Device#_checkDevice
* @private
*/
_checkDevice: function () {
@@ -443,10 +439,11 @@ Phaser.Device.prototype = {
/**
* Check whether the host environment support 3D CSS.
* @method _checkCSS3D
* @method Phaser.Device#_checkCSS3D
* @private
*/
_checkCSS3D: function () {
var el = document.createElement('p');
var has3d;
var transforms = {
@@ -456,6 +453,7 @@ Phaser.Device.prototype = {
'MozTransform': '-moz-transform',
'transform': 'transform'
};
// Add it to the body to get the computed style.
document.body.insertBefore(el, null);
@@ -465,6 +463,7 @@ Phaser.Device.prototype = {
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
}
}
document.body.removeChild(el);
this.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
@@ -472,20 +471,30 @@ Phaser.Device.prototype = {
/**
* Check whether the host environment can play audio.
* @method canPlayAudio
* @method Phaser.Device#canPlayAudio
* @param {string} type - One of 'mp3, 'ogg', 'm4a', 'wav', 'webm'.
* @return {boolean} True if the given file type is supported by the browser, otherwise false.
*/
canPlayAudio: function (type) {
if (type == 'mp3' && this.mp3) {
if (type == 'mp3' && this.mp3)
{
return true;
} else if (type == 'ogg' && (this.ogg || this.opus)) {
}
else if (type == 'ogg' && (this.ogg || this.opus))
{
return true;
} else if (type == 'm4a' && this.m4a) {
}
else if (type == 'm4a' && this.m4a)
{
return true;
} else if (type == 'wav' && this.wav) {
}
else if (type == 'wav' && this.wav)
{
return true;
} else if (type == 'webm' && this.webm) {
}
else if (type == 'webm' && this.webm)
{
return true;
}
@@ -495,21 +504,23 @@ Phaser.Device.prototype = {
/**
* Check whether the console is open.
* @method isConsoleOpen
* @return {boolean} True if console is open.
* @method Phaser.Device#isConsoleOpen
* @return {boolean} True if the browser dev console is open.
*/
isConsoleOpen: function () {
if (window.console && window.console['firebug']) {
if (window.console && window.console['firebug'])
{
return true;
}
if (window.console) {
if (window.console)
{
console.profile();
console.profileEnd();
if (console.clear) {
if (console.clear)
{
console.clear();
}
+22 -22
View File
@@ -2,10 +2,8 @@
* @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.RequestAnimationFrame
*/
/**
* Abstracts away the use of RAF or setTimeOut for the core game update loop.
*
@@ -39,26 +37,28 @@ Phaser.RequestAnimationFrame = function(game) {
'o'
];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++)
{
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
}
};
Phaser.RequestAnimationFrame.prototype = {
/**
* The function called by the update
* @property _onLoop
* @private
**/
_onLoop: null,
*/
this._onLoop = null;
};
Phaser.RequestAnimationFrame.prototype = {
/**
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
* @method start
**/
* @method Phaser.RequestAnimationFrame#start
*/
start: function () {
this.isRunning = true;
@@ -90,9 +90,9 @@ Phaser.RequestAnimationFrame.prototype = {
/**
* The update method for the requestAnimationFrame
* @method updateRAF
* @param {number} time - Description.
**/
* @method Phaser.RequestAnimationFrame#updateRAF
* @param {number} time - A timestamp, either from RAF or setTimeOut
*/
updateRAF: function (time) {
this.game.update(time);
@@ -103,8 +103,8 @@ Phaser.RequestAnimationFrame.prototype = {
/**
* The update method for the setTimeout.
* @method updateSetTimeout
**/
* @method Phaser.RequestAnimationFrame#updateSetTimeout
*/
updateSetTimeout: function () {
this.game.update(Date.now());
@@ -115,8 +115,8 @@ Phaser.RequestAnimationFrame.prototype = {
/**
* Stops the requestAnimationFrame from running.
* @method stop
**/
* @method Phaser.RequestAnimationFrame#stop
*/
stop: function () {
if (this._isSetTimeOut)
@@ -134,18 +134,18 @@ Phaser.RequestAnimationFrame.prototype = {
/**
* Is the browser using setTimeout?
* @method isSetTimeOut
* @method Phaser.RequestAnimationFrame#isSetTimeOut
* @return {boolean}
**/
*/
isSetTimeOut: function () {
return this._isSetTimeOut;
},
/**
* Is the browser using requestAnimationFrame?
* @method isRAF
* @method Phaser.RequestAnimationFrame#isRAF
* @return {boolean}
**/
*/
isRAF: function () {
return (this._isSetTimeOut === false);
}
+46 -29
View File
@@ -2,7 +2,6 @@
* @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.StageScaleMode
*/
/**
@@ -156,14 +155,30 @@ Phaser.StageScaleMode = function (game, width, height) {
};
/**
* @constant
* @type {number}
*/
Phaser.StageScaleMode.EXACT_FIT = 0;
/**
* @constant
* @type {number}
*/
Phaser.StageScaleMode.NO_SCALE = 1;
/**
* @constant
* @type {number}
*/
Phaser.StageScaleMode.SHOW_ALL = 2;
Phaser.StageScaleMode.prototype = {
/**
* Description.
* @method startFullScreen
* Tries to enter the browser into full screen mode.
* Please note that this needs to be supported by the web browser and isn't the same thing as setting your game to fill the browser.
* @method Phaser.StageScaleMode#startFullScreen
*/
startFullScreen: function () {
@@ -193,8 +208,8 @@ Phaser.StageScaleMode.prototype = {
},
/**
* Description.
* @method stopFullScreen
* Stops full screen mode if the browser is in it.
* @method Phaser.StageScaleMode#stopFullScreen
*/
stopFullScreen: function () {
@@ -214,8 +229,8 @@ Phaser.StageScaleMode.prototype = {
},
/**
* Description.
* @method checkOrientationState
* Checks if the browser is in the correct orientation for your game (if forceLandscape or forcePortrait have been set)
* @method Phaser.StageScaleMode#checkOrientationState
*/
checkOrientationState: function () {
@@ -244,8 +259,8 @@ Phaser.StageScaleMode.prototype = {
/**
* Handle window.orientationchange events
* @method checkOrientation
* @param {Description} event - Description.
* @method Phaser.StageScaleMode#checkOrientation
* @param {Event} event - The orientationchange event data.
*/
checkOrientation: function (event) {
@@ -269,8 +284,8 @@ Phaser.StageScaleMode.prototype = {
/**
* Handle window.resize events
* @method checkResize
* @param {Description} event - Description.
* @method Phaser.StageScaleMode#checkResize
* @param {Event} event - The resize event data.
*/
checkResize: function (event) {
@@ -300,7 +315,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Re-calculate scale mode and update screen size.
* @method refresh
* @method Phaser.StageScaleMode#refresh
*/
refresh: function () {
@@ -335,7 +350,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Set screen size automatically based on the scaleMode.
* @param {Description} force - Description.
* @param {Description} force - If force is true it will try to resize the game regardless of the document dimensions.
*/
setScreenSize: function (force) {
@@ -384,8 +399,8 @@ Phaser.StageScaleMode.prototype = {
},
/**
* Description.
* @method setSize
* Sets the canvas style width and height values based on minWidth/Height and maxWidth/Height.
* @method Phaser.StageScaleMode#setSize
*/
setSize: function () {
@@ -451,8 +466,8 @@ Phaser.StageScaleMode.prototype = {
},
/**
* Description.
* @method setMaximum
* Sets this.width equal to window.innerWidth and this.height equal to window.innerHeight
* @method Phaser.StageScaleMode#setMaximum
*/
setMaximum: function () {
@@ -462,8 +477,8 @@ Phaser.StageScaleMode.prototype = {
},
/**
* Description.
* @method setShowAll
* Calculates the multiplier needed to scale the game proportionally.
* @method Phaser.StageScaleMode#setShowAll
*/
setShowAll: function () {
@@ -475,15 +490,15 @@ Phaser.StageScaleMode.prototype = {
},
/**
* Description.
* @method setExactFit
* Sets the width and height values of the canvas, no larger than the maxWidth/Height.
* @method Phaser.StageScaleMode#setExactFit
*/
setExactFit: function () {
var availableWidth = window.innerWidth - 0;
var availableHeight = window.innerHeight - 5;
console.log('available', availableWidth, availableHeight);
// console.log('available', availableWidth, availableHeight);
if (this.maxWidth && availableWidth > this.maxWidth)
{
@@ -510,8 +525,9 @@ Phaser.StageScaleMode.prototype = {
};
/**
* Get
* @return {boolean}
* @name Phaser.StageScaleMode#isFullScreen
* @property {boolean} isFullScreen - Returns true if the browser is in full screen mode, otherwise false.
* @readonly
*/
Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", {
@@ -529,8 +545,9 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", {
});
/**
* Get
* @return {number}
* @name Phaser.StageScaleMode#isPortrait
* @property {boolean} isPortrait - Returns true if the browser dimensions match a portrait display.
* @readonly
*/
Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", {
@@ -541,8 +558,9 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", {
});
/**
* Get
* @return {number}
* @name Phaser.StageScaleMode#isLandscape
* @property {boolean} isLandscape - Returns true if the browser dimensions match a landscape display.
* @readonly
*/
Object.defineProperty(Phaser.StageScaleMode.prototype, "isLandscape", {
@@ -551,4 +569,3 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isLandscape", {
}
});