Skip to content

Commit 96d750b

Browse files
committed
Documented BitmapText and DynamicBitmapText.
Moved BitmapFontData typedefs to the BitmapText class file.
1 parent 25f1ded commit 96d750b

4 files changed

Lines changed: 113 additions & 105 deletions

File tree

src/gameobjects/bitmaptext/GetBitmapTextSize.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
/**
88
* @typedef {object} BitmapTextSize
99
*
10-
* @property {GlobalBitmapTextSize} global - The position and size of the BitmapText, taking into consideration the position and scale of the Game Object.
11-
* @property {LocalBitmapTextSize} local - The position and size of the BitmapText, taking just the font size into consideration.
10+
* @property {GlobalBitmapTextSize} global - The position and size of the BitmapText, taking into account the position and scale of the Game Object.
11+
* @property {LocalBitmapTextSize} local - The position and size of the BitmapText, taking just the font size into account.
1212
*/
1313

1414
/**
15+
* The position and size of the Bitmap Text in global space, taking into account the Game Object's scale and world position.
16+
*
1517
* @typedef {object} GlobalBitmapTextSize
1618
*
17-
* @property {number} x - The x position of the BitmapText, taking into consideration the x position and scale of the Game Object.
18-
* @property {number} y - The y position of the BitmapText, taking into consideration the y position and scale of the Game Object.
19-
* @property {number} width - The width of the BitmapText, taking into consideration the x scale of the Game Object.
20-
* @property {number} width - The height of the BitmapText, taking into consideration the y scale of the Game Object.
19+
* @property {number} x - The x position of the BitmapText, taking into account the x position and scale of the Game Object.
20+
* @property {number} y - The y position of the BitmapText, taking into account the y position and scale of the Game Object.
21+
* @property {number} width - The width of the BitmapText, taking into account the x scale of the Game Object.
22+
* @property {number} width - The height of the BitmapText, taking into account the y scale of the Game Object.
2123
*/
2224

2325
/**
26+
* The position and size of the Bitmap Text in local space, taking just the font size into account.
27+
*
2428
* @typedef {object} LocalBitmapTextSize
2529
*
2630
* @property {number} x - The x position of the BitmapText.
@@ -35,16 +39,16 @@
3539
* Returns a BitmapTextSize object that contains global and local variants of the Game Objects x and y coordinates and
3640
* its width and height.
3741
*
38-
* The global position and size take into consideration the Game Object's position and scale.
42+
* The global position and size take into account the Game Object's position and scale.
3943
*
40-
* The local position and size just takes into consideration the font data.
44+
* The local position and size just takes into account the font data.
4145
*
4246
* @function GetBitmapTextSize
4347
* @since 3.0.0
4448
* @private
4549
*
4650
* @param {(Phaser.GameObjects.DynamicBitmapText|Phaser.GameObjects.BitmapText)} src - The BitmapText to calculate the position, width and height of.
47-
* @param {boolean} round - Whether to round the results to the nearest integer.
51+
* @param {boolean} [round] - Whether to round the results to the nearest integer.
4852
*
4953
* @return {BitmapTextSize} The calculated position, width and height of the BitmapText.
5054
*/

src/gameobjects/bitmaptext/ParseXMLBitmapFont.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,6 @@ function getValue (node, attribute)
1414
return parseInt(node.getAttribute(attribute), 10);
1515
}
1616

17-
// TODO: These typedefs should be kept somewhere else.
18-
// TODO: Elaborate on the kerning property description.
19-
20-
/**
21-
* The font data for an individual character of a Bitmap Font.
22-
*
23-
* Describes the character's position, size, offset and kerning.
24-
*
25-
* @typedef {object} BitmapFontCharacterData
26-
*
27-
* @property {number} x - The x position of the character.
28-
* @property {number} y - The y position of the character.
29-
* @property {number} width - The width of the character.
30-
* @property {number} height - The height of the character.
31-
* @property {number} centerX - The center x position of the character.
32-
* @property {number} centerY - The center y position of the character.
33-
* @property {number} xOffset - The x offset of the character.
34-
* @property {number} yOffset - The y offset of the character.
35-
* @property {object} data - Extra data for the character.
36-
* @property {object} kerning - Kerning values. [description]
37-
*/
38-
39-
/**
40-
* Bitmap Font data that can be used by a BitmapText Game Object.
41-
*
42-
* @typedef {object} BitmapFontData
43-
*
44-
* @property {string} font - The name of the font.
45-
* @property {number} size - The size of the font.
46-
* @property {number} lineHeight - The line height of the font.
47-
* @property {boolean} retroFont - Whether this font is a retro font (monospace).
48-
* @property {Object.<number, BitmapFontCharacterData>} chars - The character data of the font, keyed by character code. Each character datum includes a position, size, offset and more.
49-
*/
50-
5117
/**
5218
* Parse an XML font so you can pass it to the BitmapText constructor and create a BitmapText object.
5319
*

src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var DynamicBitmapText = new Class({
8585
GameObject.call(this, scene, 'DynamicBitmapText');
8686

8787
/**
88-
* [description]
88+
* The key of the Bitmap Font used by this Bitmap Text.
8989
*
9090
* @name Phaser.GameObjects.DynamicBitmapText#font
9191
* @type {string}
@@ -96,16 +96,16 @@ var DynamicBitmapText = new Class({
9696
var entry = this.scene.sys.cache.bitmapFont.get(font);
9797

9898
/**
99-
* [description]
99+
* The data of the Bitmap Font used by this Bitmap Text.
100100
*
101101
* @name Phaser.GameObjects.DynamicBitmapText#fontData
102-
* @type {object}
102+
* @type {BitmapFontData}
103103
* @since 3.0.0
104104
*/
105105
this.fontData = entry.data;
106106

107107
/**
108-
* [description]
108+
* The text that this Bitmap Text object displays.
109109
*
110110
* @name Phaser.GameObjects.DynamicBitmapText#text
111111
* @type {string}
@@ -114,7 +114,7 @@ var DynamicBitmapText = new Class({
114114
this.text = '';
115115

116116
/**
117-
* [description]
117+
* The size of this Bitmap Text.
118118
*
119119
* @name Phaser.GameObjects.DynamicBitmapText#fontSize
120120
* @type {number}
@@ -140,17 +140,17 @@ var DynamicBitmapText = new Class({
140140
this.initPipeline('TextureTintPipeline');
141141

142142
/**
143-
* [description]
143+
* An object that describes the size of this BitmapText.
144144
*
145145
* @name Phaser.GameObjects.DynamicBitmapText#_bounds
146-
* @type {TextBounds}
146+
* @type {BitmapTextSize}
147147
* @private
148148
* @since 3.0.0
149149
*/
150150
this._bounds = this.getTextBounds();
151151

152152
/**
153-
* [description]
153+
* The horizontal scroll position of the Bitmap Text.
154154
*
155155
* @name Phaser.GameObjects.DynamicBitmapText#scrollX
156156
* @type {number}
@@ -160,7 +160,7 @@ var DynamicBitmapText = new Class({
160160
this.scrollX = 0;
161161

162162
/**
163-
* [description]
163+
* The vertical scroll position of the Bitmap Text.
164164
*
165165
* @name Phaser.GameObjects.DynamicBitmapText#scrollY
166166
* @type {number}
@@ -170,7 +170,7 @@ var DynamicBitmapText = new Class({
170170
this.scrollY = 0;
171171

172172
/**
173-
* [description]
173+
* The crop width of the Bitmap Text.
174174
*
175175
* @name Phaser.GameObjects.DynamicBitmapText#cropWidth
176176
* @type {number}
@@ -180,7 +180,7 @@ var DynamicBitmapText = new Class({
180180
this.cropWidth = 0;
181181

182182
/**
183-
* [description]
183+
* The crop height of the Bitmap Text.
184184
*
185185
* @name Phaser.GameObjects.DynamicBitmapText#cropHeight
186186
* @type {number}
@@ -200,13 +200,13 @@ var DynamicBitmapText = new Class({
200200
},
201201

202202
/**
203-
* [description]
203+
* Set the crop size of this Bitmap Text.
204204
*
205205
* @method Phaser.GameObjects.DynamicBitmapText#setSize
206206
* @since 3.0.0
207207
*
208-
* @param {number} width - [description]
209-
* @param {number} height - [description]
208+
* @param {number} width - The width of the crop.
209+
* @param {number} height - The height of the crop.
210210
*
211211
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
212212
*/
@@ -236,12 +236,12 @@ var DynamicBitmapText = new Class({
236236
},
237237

238238
/**
239-
* [description]
239+
* Set the font size of this Bitmap Text.
240240
*
241241
* @method Phaser.GameObjects.DynamicBitmapText#setFontSize
242242
* @since 3.0.0
243243
*
244-
* @param {number} size - [description]
244+
* @param {number} size - The font size to set.
245245
*
246246
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
247247
*/
@@ -253,7 +253,9 @@ var DynamicBitmapText = new Class({
253253
},
254254

255255
/**
256-
* [description]
256+
* Set the content of this BitmapText.
257+
*
258+
* An array of strings will be converted multi-line text.
257259
*
258260
* @method Phaser.GameObjects.DynamicBitmapText#setText
259261
* @since 3.0.0
@@ -285,12 +287,12 @@ var DynamicBitmapText = new Class({
285287
},
286288

287289
/**
288-
* [description]
290+
* Set the horizontal scroll position of this Bitmap Text.
289291
*
290292
* @method Phaser.GameObjects.DynamicBitmapText#setScrollX
291293
* @since 3.0.0
292294
*
293-
* @param {number} value - [description]
295+
* @param {number} value - The horizontal scroll position to set.
294296
*
295297
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
296298
*/
@@ -302,12 +304,12 @@ var DynamicBitmapText = new Class({
302304
},
303305

304306
/**
305-
* [description]
307+
* Set the vertical scroll position of this Bitmap Text.
306308
*
307309
* @method Phaser.GameObjects.DynamicBitmapText#setScrollY
308310
* @since 3.0.0
309311
*
310-
* @param {number} value - [description]
312+
* @param {number} value - The vertical scroll position to set.
311313
*
312314
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
313315
*/
@@ -319,14 +321,21 @@ var DynamicBitmapText = new Class({
319321
},
320322

321323
/**
322-
* [description]
324+
* Calculate the bounds of this Bitmap Text.
325+
*
326+
* An object is returned that contains the position, width and height of the Bitmap Text in local and global
327+
* contexts.
328+
*
329+
* Local size is based on just the font size and a [0, 0] position.
330+
*
331+
* Global size takes into account the Game Object's scale and world position.
323332
*
324333
* @method Phaser.GameObjects.DynamicBitmapText#getTextBounds
325334
* @since 3.0.0
326335
*
327-
* @param {boolean} round - [description]
336+
* @param {boolean} [round] - Whether to round the results to the nearest integer.
328337
*
329-
* @return {TextBounds} [description]
338+
* @return {BitmapTextSize} An object that describes the size of this Bitmap Text.
330339
*/
331340
getTextBounds: function (round)
332341
{
@@ -339,10 +348,11 @@ var DynamicBitmapText = new Class({
339348
},
340349

341350
/**
342-
* [description]
351+
* The width of this Bitmap Text.
343352
*
344353
* @name Phaser.GameObjects.DynamicBitmapText#width
345354
* @type {number}
355+
* @readonly
346356
* @since 3.0.0
347357
*/
348358
width: {
@@ -356,7 +366,7 @@ var DynamicBitmapText = new Class({
356366
},
357367

358368
/**
359-
* [description]
369+
* The height of this Bitmap Text.
360370
*
361371
* @name Phaser.GameObjects.DynamicBitmapText#height
362372
* @type {number}
@@ -373,12 +383,12 @@ var DynamicBitmapText = new Class({
373383
},
374384

375385
/**
376-
* [description]
386+
* Build a JSON representation of this Bitmap Text.
377387
*
378388
* @method Phaser.GameObjects.DynamicBitmapText#toJSON
379389
* @since 3.0.0
380390
*
381-
* @return {JSONBitmapText} [description]
391+
* @return {JSONBitmapText} The JSON representation of this Bitmap Text.
382392
*/
383393
toJSON: function ()
384394
{

0 commit comments

Comments
 (0)