Added jsdocs

This commit is contained in:
Richard Davey 2018-02-05 23:59:51 +00:00
parent 6df51372d5
commit a8eae2bab7
11 changed files with 454 additions and 25 deletions

View file

@ -4,6 +4,33 @@ var GameObject = require('../../GameObject');
var GetBitmapTextSize = require('../GetBitmapTextSize');
var Render = require('./DynamicBitmapTextRender');
/**
* [description]
*
* @class DynamicBitmapText
* @extends Phaser.GameObjects.GameObject
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @extends Phaser.GameObjects.Components.Alpha
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.Origin
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.Texture
* @extends Phaser.GameObjects.Components.Tint
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
* @extends Phaser.GameObjects.Components.ScrollFactor
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. It can only belong to one Scene at any given time.
* @param {number} [x=0] - The x coordinate of this Game Object in world space.
* @param {number} [y=0] - The y coordinate of this Game Object in world space.
* @param {string} font - [description]
* @param {string|string[]} [text] - [description]
* @param {number} [size] - [description]
*/
var DynamicBitmapText = new Class({
Extends: GameObject,
@ -30,14 +57,42 @@ var DynamicBitmapText = new Class({
GameObject.call(this, scene, 'DynamicBitmapText');
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#font
* @type {string}
* @since 3.0.0
*/
this.font = font;
var entry = this.scene.sys.cache.bitmapFont.get(font);
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#fontData
* @type {object}
* @since 3.0.0
*/
this.fontData = entry.data;
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#text
* @type {string}
* @since 3.0.0
*/
this.text = (Array.isArray(text)) ? text.join('\n') : text;
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#fontSize
* @type {number}
* @since 3.0.0
*/
this.fontSize = size || this.fontData.size;
this.setTexture(entry.texture, entry.frame);
@ -45,17 +100,77 @@ var DynamicBitmapText = new Class({
this.setOrigin(0, 0);
this.initPipeline('TextureTintPipeline');
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#_bounds
* @type {object}
* @private
* @since 3.0.0
*/
this._bounds = this.getTextBounds();
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#scrollX
* @type {number}
* @default 0
* @since 3.0.0
*/
this.scrollX = 0;
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#scrollY
* @type {number}
* @default 0
* @since 3.0.0
*/
this.scrollY = 0;
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#cropWidth
* @type {number}
* @default 0
* @since 3.0.0
*/
this.cropWidth = 0;
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#cropHeight
* @type {number}
* @default 0
* @since 3.0.0
*/
this.cropHeight = 0;
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#displayCallback;
* @type {function}
* @since 3.0.0
*/
this.displayCallback;
},
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#setSize
* @since 3.0.0
*
* @param {number} width - [description]
* @param {number} height - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
*/
setSize: function (width, height)
{
this.cropWidth = width;
@ -64,6 +179,16 @@ var DynamicBitmapText = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#setDisplayCallback
* @since 3.0.0
*
* @param {function} callback - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
*/
setDisplayCallback: function (callback)
{
this.displayCallback = callback;
@ -71,6 +196,16 @@ var DynamicBitmapText = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#setFontSize
* @since 3.0.0
*
* @param {number} size - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
*/
setFontSize: function (size)
{
this.fontSize = size;
@ -78,13 +213,38 @@ var DynamicBitmapText = new Class({
return this;
},
setText: function (text)
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#setText
* @since 3.0.0
*
* @param {string|string[]} text - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
*/
setText: function (value)
{
this.text = text;
if (Array.isArray(value))
{
value = value.join('\n');
}
this.text = value;
return this;
},
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#setScrollX
* @since 3.0.0
*
* @param {number} value - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
*/
setScrollX: function (value)
{
this.scrollX = value;
@ -92,6 +252,16 @@ var DynamicBitmapText = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#setScrollY
* @since 3.0.0
*
* @param {number} value - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
*/
setScrollY: function (value)
{
this.scrollY = value;
@ -114,6 +284,16 @@ var DynamicBitmapText = new Class({
// }
// }
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#getTextBounds
* @since 3.0.0
*
* @param {boolean} round - [description]
*
* @return {object} [description]
*/
getTextBounds: function (round)
{
// local = the BitmapText based on fontSize and 0x0 coords
@ -124,6 +304,13 @@ var DynamicBitmapText = new Class({
return this._bounds;
},
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#width
* @type {number}
* @since 3.0.0
*/
width: {
get: function ()
@ -134,6 +321,13 @@ var DynamicBitmapText = new Class({
},
/**
* [description]
*
* @name Phaser.GameObjects.DynamicBitmapText#height
* @type {number}
* @since 3.0.0
*/
height: {
get: function ()
@ -144,6 +338,14 @@ var DynamicBitmapText = new Class({
},
/**
* [description]
*
* @method Phaser.GameObjects.DynamicBitmapText#toJSON
* @since 3.0.0
*
* @return {object} [description]
*/
toJSON: function ()
{
var out = Components.ToJSON(this);

View file

@ -1,5 +1,19 @@
var GameObject = require('../../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.DynamicBitmapText#renderCanvas
* @since 3.0.0
* @private
*
* @param {Phaser.Renderer.CanvasRenderer} renderer - A reference to the current active Canvas renderer.
* @param {Phaser.GameObjects.DynamicBitmapText} src - The Game Object being rendered in this call.
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
*/
var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
{
var text = src.text;

View file

@ -3,8 +3,18 @@ var BuildGameObject = require('../../BuildGameObject');
var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
// When registering a factory function 'this' refers to the GameObjectCreator context.
/**
* Creates a new Dynamic Bitmap Text Game Object and returns it.
*
* Note: This method will only be available if the Dynamic Bitmap Text Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectCreator#dynamicBitmapText
* @since 3.0.0
*
* @param {object} config - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} The Game Object that was created.
*/
GameObjectCreator.register('dynamicBitmapText', function (config)
{
var font = GetAdvancedValue(config, 'font', '');
@ -18,3 +28,5 @@ GameObjectCreator.register('dynamicBitmapText', function (config)
return bitmapText;
});
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,6 +1,27 @@
var DynamicBitmapText = require('./DynamicBitmapText');
var GameObjectFactory = require('../../GameObjectFactory');
/**
* Creates a new Dynamic Bitmap Text Game Object and adds it to the Scene.
*
* Note: This method will only be available if the Dynamic Bitmap Text Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectFactory#dynamicBitmapText
* @since 3.0.0
*
* @param {number} x - The x position of the Game Object.
* @param {number} y - The y position of the Game Object.
* @param {string} font - [description]
* @param {string|string[]} [text] - [description]
* @param {number} [size] - [description]
*
* @return {Phaser.GameObjects.DynamicBitmapText} The Game Object that was created.
*/
GameObjectFactory.register('dynamicBitmapText', function (x, y, font, text, size)
{
return this.displayList.add(new DynamicBitmapText(this.scene, x, y, font, text, size));
});
// When registering a factory function 'this' refers to the GameObjectFactory context.
//
// There are several properties available to use:
@ -8,8 +29,3 @@ var GameObjectFactory = require('../../GameObjectFactory');
// this.scene - a reference to the Scene that owns the GameObjectFactory
// this.displayList - a reference to the Display List the Scene owns
// this.updateList - a reference to the Update List the Scene owns
GameObjectFactory.register('dynamicBitmapText', function (x, y, font, text, size)
{
return this.displayList.add(new DynamicBitmapText(this.scene, x, y, font, text, size));
});

View file

@ -1,9 +1,19 @@
var GameObject = require('../../GameObject');
var TransformMatrix = require('../../components/TransformMatrix');
var Utils = require('../../../renderer/webgl/Utils');
var tempMatrix = new TransformMatrix();
var tempMatrixChar = new TransformMatrix();
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.DynamicBitmapText#renderWebGL
* @since 3.0.0
* @private
*
* @param {Phaser.Renderer.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
* @param {Phaser.GameObjects.DynamicBitmapText} gameObject - The Game Object being rendered in this call.
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
*/
var DynamicBitmapTextWebGLRenderer = function (renderer, bitmapText, interpolationPercentage, camera)
{
var text = bitmapText.text;

View file

@ -6,6 +6,34 @@ var ParseFromAtlas = require('../ParseFromAtlas');
var ParseRetroFont = require('../ParseRetroFont');
var Render = require('./BitmapTextRender');
/**
* [description]
*
* @class BitmapText
* @extends Phaser.GameObjects.GameObject
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @extends Phaser.GameObjects.Components.Alpha
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.Origin
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.ScaleMode
* @extends Phaser.GameObjects.Components.Texture
* @extends Phaser.GameObjects.Components.Tint
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
* @extends Phaser.GameObjects.Components.ScrollFactor
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. It can only belong to one Scene at any given time.
* @param {number} [x=0] - The x coordinate of this Game Object in world space.
* @param {number} [y=0] - The y coordinate of this Game Object in world space.
* @param {string} font - [description]
* @param {string|string[]} [text] - [description]
* @param {number} [size] - [description]
*/
var BitmapText = new Class({
Extends: GameObject,
@ -33,14 +61,42 @@ var BitmapText = new Class({
GameObject.call(this, scene, 'BitmapText');
/**
* [description]
*
* @name Phaser.GameObjects.BitmapText#font
* @type {string}
* @since 3.0.0
*/
this.font = font;
var entry = this.scene.sys.cache.bitmapFont.get(font);
/**
* [description]
*
* @name Phaser.GameObjects.BitmapText#fontData
* @type {object}
* @since 3.0.0
*/
this.fontData = entry.data;
/**
* [description]
*
* @name Phaser.GameObjects.BitmapText#text
* @type {string}
* @since 3.0.0
*/
this.text = (Array.isArray(text)) ? text.join('\n') : text;
/**
* [description]
*
* @name Phaser.GameObjects.BitmapText#fontSize
* @type {number}
* @since 3.0.0
*/
this.fontSize = size || this.fontData.size;
this.setTexture(entry.texture, entry.frame);
@ -48,9 +104,27 @@ var BitmapText = new Class({
this.setOrigin(0, 0);
this.initPipeline('TextureTintPipeline');
/**
* [description]
*
* @name Phaser.GameObjects.BitmapText#_bounds
* @type {object}
* @private
* @since 3.0.0
*/
this._bounds = this.getTextBounds();
},
/**
* [description]
*
* @method Phaser.GameObjects.BitmapText#setFontSize
* @since 3.0.0
*
* @param {number} size - [description]
*
* @return {Phaser.GameObjects.BitmapText} This Game Object.
*/
setFontSize: function (size)
{
this.fontSize = size;
@ -58,9 +132,24 @@ var BitmapText = new Class({
return this;
},
setText: function (text)
/**
* [description]
*
* @method Phaser.GameObjects.BitmapText#setText
* @since 3.0.0
*
* @param {string|string[]} text - [description]
*
* @return {Phaser.GameObjects.BitmapText} This Game Object.
*/
setText: function (value)
{
this.text = text;
if (Array.isArray(value))
{
value = value.join('\n');
}
this.text = value;
return this;
},
@ -80,6 +169,16 @@ var BitmapText = new Class({
// }
// }
/**
* [description]
*
* @method Phaser.GameObjects.BitmapText#getTextBounds
* @since 3.0.0
*
* @param {boolean} round - [description]
*
* @return {object} [description]
*/
getTextBounds: function (round)
{
// local = the BitmapText based on fontSize and 0x0 coords
@ -90,6 +189,13 @@ var BitmapText = new Class({
return this._bounds;
},
/**
* [description]
*
* @name Phaser.GameObjects.BitmapText#width
* @type {number}
* @since 3.0.0
*/
width: {
get: function ()
@ -100,6 +206,13 @@ var BitmapText = new Class({
},
/**
* [description]
*
* @name Phaser.GameObjects.BitmapText#height
* @type {number}
* @since 3.0.0
*/
height: {
get: function ()
@ -110,6 +223,14 @@ var BitmapText = new Class({
},
/**
* [description]
*
* @method Phaser.GameObjects.BitmapText#toJSON
* @since 3.0.0
*
* @return {object} [description]
*/
toJSON: function ()
{
var out = Components.ToJSON(this);

View file

@ -1,5 +1,19 @@
var GameObject = require('../../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.BitmapText#renderCanvas
* @since 3.0.0
* @private
*
* @param {Phaser.Renderer.CanvasRenderer} renderer - A reference to the current active Canvas renderer.
* @param {Phaser.GameObjects.BitmapText} src - The Game Object being rendered in this call.
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
*/
var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
{
var text = src.text;

View file

@ -4,8 +4,18 @@ var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var GetValue = require('../../../utils/object/GetValue');
// When registering a factory function 'this' refers to the GameObjectCreator context.
/**
* Creates a new Bitmap Text Game Object and returns it.
*
* Note: This method will only be available if the Bitmap Text Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectCreator#bitmapText
* @since 3.0.0
*
* @param {object} config - [description]
*
* @return {Phaser.GameObjects.BitmapText} The Game Object that was created.
*/
GameObjectCreator.register('bitmapText', function (config)
{
var font = GetValue(config, 'font', '');
@ -19,3 +29,5 @@ GameObjectCreator.register('bitmapText', function (config)
return bitmapText;
});
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,6 +1,27 @@
var BitmapText = require('./BitmapText');
var GameObjectFactory = require('../../GameObjectFactory');
/**
* Creates a new Bitmap Text Game Object and adds it to the Scene.
*
* Note: This method will only be available if the Bitmap Text Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectFactory#bitmapText
* @since 3.0.0
*
* @param {number} x - The x position of the Game Object.
* @param {number} y - The y position of the Game Object.
* @param {string} font - [description]
* @param {string|string[]} [text] - [description]
* @param {number} [size] - [description]
*
* @return {Phaser.GameObjects.BitmapText} The Game Object that was created.
*/
GameObjectFactory.register('bitmapText', function (x, y, font, text, size)
{
return this.displayList.add(new BitmapText(this.scene, x, y, font, text, size));
});
// When registering a factory function 'this' refers to the GameObjectFactory context.
//
// There are several properties available to use:
@ -8,8 +29,3 @@ var GameObjectFactory = require('../../GameObjectFactory');
// this.scene - a reference to the Scene that owns the GameObjectFactory
// this.displayList - a reference to the Display List the Scene owns
// this.updateList - a reference to the Update List the Scene owns
GameObjectFactory.register('bitmapText', function (x, y, font, text, size)
{
return this.displayList.add(new BitmapText(this.scene, x, y, font, text, size));
});

View file

@ -1,7 +1,19 @@
var GameObject = require('../../GameObject');
var TransformMatrix = require('../../components/TransformMatrix');
var tempMatrix = new TransformMatrix();
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.BitmapText#renderWebGL
* @since 3.0.0
* @private
*
* @param {Phaser.Renderer.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
* @param {Phaser.GameObjects.BitmapText} gameObject - The Game Object being rendered in this call.
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
*/
var BitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera)
{
var text = gameObject.text;

View file

@ -32,7 +32,7 @@ var GameObject = require('../GameObject');
* @extends Phaser.GameObjects.Components.Visible
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. It can only belong to one Scene at any given time.
* @param {number} [x==] - The x coordinate of this Game Object in world space.
* @param {number} [x=0] - The x coordinate of this Game Object in world space.
* @param {number} [y=0] - The y coordinate of this Game Object in world space.
* @param {string} [texture='__DEFAULT'] - The key of the texture this Game Object will use for rendering. The Texture must already exist in the Texture Manager.
* @param {string|integer} [frame=0] - The Frame of the Texture that this Game Object will use. Only set if the Texture has multiple frames, such as a Texture Atlas or Sprite Sheet.