2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2015-02-25 03:36:23 +00:00
|
|
|
* @copyright 2015 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-06-06 10:35:08 +00:00
|
|
|
* BitmapText objects work by taking a texture file and an XML or JSON file that describes the font structure.
|
2015-03-23 15:03:53 +00:00
|
|
|
* It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to
|
|
|
|
* match the font structure.
|
|
|
|
*
|
|
|
|
* BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability
|
2015-06-06 10:35:08 +00:00
|
|
|
* to use Web Fonts, however you trade this flexibility for rendering speed. You can also create visually compelling BitmapTexts by
|
|
|
|
* processing the font texture in an image editor, applying fills and any other effects required.
|
2013-11-28 15:57:09 +00:00
|
|
|
*
|
2015-06-03 03:23:22 +00:00
|
|
|
* To create multi-line text insert \r, \n or \r\n escape codes into the text string.
|
|
|
|
*
|
2015-06-03 04:28:07 +00:00
|
|
|
* If you are having performance issues due to the volume of sprites being rendered, and do not require the text to be constantly
|
|
|
|
* updating, you can use BitmapText.generateTexture to create a static texture from this BitmapText.
|
|
|
|
*
|
2015-06-03 03:23:22 +00:00
|
|
|
* To create a BitmapText data files you can use:
|
2015-03-23 15:03:53 +00:00
|
|
|
*
|
|
|
|
* BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
|
|
|
|
* Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
|
|
|
|
* Littera (Web-based, free): http://kvazars.com/littera/
|
2013-11-01 17:28:09 +00:00
|
|
|
*
|
2015-07-16 11:30:55 +00:00
|
|
|
* For most use cases it is recommended to use XML. If you wish to use JSON, the formatting should be equal to the result of
|
|
|
|
* converting a valid XML file through the popular X2JS library. An online tool for conversion can be found here: http://codebeautify.org/xmltojson
|
2015-06-06 10:35:08 +00:00
|
|
|
*
|
2014-09-16 16:35:08 +00:00
|
|
|
* @class Phaser.BitmapText
|
2013-10-01 12:54:29 +00:00
|
|
|
* @constructor
|
2015-06-03 03:23:22 +00:00
|
|
|
* @extends PIXI.DisplayObjectContainer
|
2015-03-01 07:00:17 +00:00
|
|
|
* @extends Phaser.Component.Core
|
|
|
|
* @extends Phaser.Component.Angle
|
|
|
|
* @extends Phaser.Component.AutoCull
|
|
|
|
* @extends Phaser.Component.Bounds
|
|
|
|
* @extends Phaser.Component.Destroy
|
|
|
|
* @extends Phaser.Component.FixedToCamera
|
|
|
|
* @extends Phaser.Component.InputEnabled
|
|
|
|
* @extends Phaser.Component.InWorld
|
|
|
|
* @extends Phaser.Component.LifeSpan
|
|
|
|
* @extends Phaser.Component.PhysicsBody
|
|
|
|
* @extends Phaser.Component.Reset
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
2015-06-03 03:23:22 +00:00
|
|
|
* @param {number} x - X coordinate to display the BitmapText object at.
|
|
|
|
* @param {number} y - Y coordinate to display the BitmapText object at.
|
|
|
|
* @param {string} font - The key of the BitmapText as stored in Phaser.Cache.
|
|
|
|
* @param {string} [text=''] - The text that will be rendered. This can also be set later via BitmapText.text.
|
|
|
|
* @param {number} [size=32] - The size the font will be rendered at in pixels.
|
|
|
|
* @param {string} [align='left'] - The alignment of multi-line text. Has no effect if there is only one line of text.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2015-06-03 03:23:22 +00:00
|
|
|
Phaser.BitmapText = function (game, x, y, font, text, size, align) {
|
2013-09-10 22:51:35 +00:00
|
|
|
|
|
|
|
x = x || 0;
|
|
|
|
y = y || 0;
|
2014-02-14 03:34:35 +00:00
|
|
|
font = font || '';
|
2013-09-10 22:51:35 +00:00
|
|
|
text = text || '';
|
2014-02-14 03:34:35 +00:00
|
|
|
size = size || 32;
|
2015-06-03 03:23:22 +00:00
|
|
|
align = align || 'left';
|
|
|
|
|
|
|
|
PIXI.DisplayObjectContainer.call(this);
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {number} type - The const type of this object.
|
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 04:40:04 +00:00
|
|
|
this.type = Phaser.BITMAPTEXT;
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-03-23 15:03:53 +00:00
|
|
|
/**
|
|
|
|
* @property {number} physicsType - The const physics body type of this object.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.physicsType = Phaser.SPRITE;
|
|
|
|
|
2015-06-03 03:23:22 +00:00
|
|
|
/**
|
|
|
|
* @property {number} textWidth - The width in pixels of the overall text area, taking into consideration multi-line text.
|
|
|
|
* @readOnly
|
|
|
|
*/
|
|
|
|
this.textWidth = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} textHeight - The height in pixels of the overall text area, taking into consideration multi-line text.
|
|
|
|
* @readOnly
|
|
|
|
*/
|
|
|
|
this.textHeight = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} anchor - The anchor value of this BitmapText.
|
|
|
|
*/
|
|
|
|
this.anchor = new Phaser.Point();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} _prevAnchor - The previous anchor value.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._prevAnchor = new Phaser.Point();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {array} _glyphs - Private tracker for the letter sprite pool.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._glyphs = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} _maxWidth - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._maxWidth = 0;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-02-14 03:34:35 +00:00
|
|
|
* @property {string} _text - Internal cache var.
|
|
|
|
* @private
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
this._text = text;
|
|
|
|
|
2015-07-16 00:29:32 +00:00
|
|
|
/**
|
|
|
|
* @property {string} _data - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._data = game.cache.getBitmapFont(font);
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-02-14 03:34:35 +00:00
|
|
|
* @property {string} _font - Internal cache var.
|
|
|
|
* @private
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
this._font = font;
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-02-14 03:34:35 +00:00
|
|
|
* @property {number} _fontSize - Internal cache var.
|
2013-11-25 03:13:04 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
this._fontSize = size;
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2014-02-14 03:34:35 +00:00
|
|
|
/**
|
2014-02-14 04:34:57 +00:00
|
|
|
* @property {string} _align - Internal cache var.
|
2014-02-14 03:34:35 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2015-06-03 03:23:22 +00:00
|
|
|
this._align = align;
|
2014-02-14 04:34:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} _tint - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._tint = 0xFFFFFF;
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-06-03 03:23:22 +00:00
|
|
|
this.updateText();
|
2015-03-23 15:03:53 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-03 03:23:22 +00:00
|
|
|
* @property {boolean} dirty - The dirty state of this object.
|
2015-03-23 15:03:53 +00:00
|
|
|
*/
|
2015-06-03 03:23:22 +00:00
|
|
|
this.dirty = false;
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-02-17 06:00:41 +00:00
|
|
|
Phaser.Component.Core.init.call(this, game, x, y, '', null);
|
2014-02-15 01:27:42 +00:00
|
|
|
|
2013-09-10 22:51:35 +00:00
|
|
|
};
|
|
|
|
|
2015-06-03 03:23:22 +00:00
|
|
|
Phaser.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
|
2013-09-10 22:51:35 +00:00
|
|
|
Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
|
|
|
|
|
2015-03-23 15:03:53 +00:00
|
|
|
Phaser.Component.Core.install.call(Phaser.BitmapText.prototype, [
|
2015-02-23 04:44:11 +00:00
|
|
|
'Angle',
|
|
|
|
'AutoCull',
|
|
|
|
'Bounds',
|
|
|
|
'Destroy',
|
|
|
|
'FixedToCamera',
|
|
|
|
'InputEnabled',
|
|
|
|
'InWorld',
|
|
|
|
'LifeSpan',
|
|
|
|
'PhysicsBody',
|
|
|
|
'Reset'
|
2015-03-23 15:03:53 +00:00
|
|
|
]);
|
2015-02-23 04:44:11 +00:00
|
|
|
|
2015-03-23 15:03:53 +00:00
|
|
|
Phaser.BitmapText.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
|
|
|
|
Phaser.BitmapText.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
|
|
|
|
Phaser.BitmapText.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
|
|
|
|
Phaser.BitmapText.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
2014-02-14 03:34:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically called by World.preUpdate.
|
2015-03-23 15:03:53 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @memberof Phaser.BitmapText
|
|
|
|
* @return {boolean} True if the BitmapText was rendered, otherwise false.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
Phaser.BitmapText.prototype.preUpdate = function () {
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-03-23 15:03:53 +00:00
|
|
|
if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-15 01:27:42 +00:00
|
|
|
|
2015-03-23 15:03:53 +00:00
|
|
|
return this.preUpdateCore();
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2014-02-14 03:34:35 +00:00
|
|
|
/**
|
2015-02-17 06:00:41 +00:00
|
|
|
* Automatically called by World.preUpdate.
|
2014-02-14 03:34:35 +00:00
|
|
|
* @method Phaser.BitmapText.prototype.postUpdate
|
|
|
|
*/
|
|
|
|
Phaser.BitmapText.prototype.postUpdate = function () {
|
2013-09-21 00:03:19 +00:00
|
|
|
|
2015-02-17 06:00:41 +00:00
|
|
|
Phaser.Component.PhysicsBody.postUpdate.call(this);
|
|
|
|
Phaser.Component.FixedToCamera.postUpdate.call(this);
|
2014-04-22 00:43:22 +00:00
|
|
|
|
2015-06-03 03:23:22 +00:00
|
|
|
if (this.body && this.body.type === Phaser.Physics.ARCADE)
|
|
|
|
{
|
|
|
|
if ((this.textWidth !== this.body.sourceWidth) || (this.textHeight !== this.body.sourceHeight))
|
|
|
|
{
|
|
|
|
this.body.setSize(this.textWidth, this.textHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The text to be displayed by this BitmapText object.
|
|
|
|
*
|
|
|
|
* It's faster to use `BitmapText.text = string`, but this is kept for backwards compatibility.
|
|
|
|
*
|
|
|
|
* @method Phaser.BitmapText.prototype.setText
|
|
|
|
* @param {string} text - The text to be displayed by this BitmapText object.
|
|
|
|
*/
|
|
|
|
Phaser.BitmapText.prototype.setText = function (text) {
|
|
|
|
|
|
|
|
this.text = text;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the input text this will scan the characters until either a newline is encountered,
|
|
|
|
* or the line exceeds maxWidth, taking into account kerning, character widths and scaling.
|
|
|
|
*
|
|
|
|
* @method Phaser.BitmapText.prototype.scanLine
|
|
|
|
* @private
|
2015-07-16 00:29:32 +00:00
|
|
|
* @param {object} data - A reference to the font object in the Phaser.Cache.
|
2015-06-03 03:23:22 +00:00
|
|
|
* @param {float} scale - The scale of the font in relation to the texture.
|
|
|
|
* @param {string} text - The text to parse.
|
|
|
|
* @return {object} An object containing the parsed characters, total pixel width and x offsets.
|
|
|
|
*/
|
|
|
|
Phaser.BitmapText.prototype.scanLine = function (data, scale, text) {
|
|
|
|
|
|
|
|
var x = 0;
|
|
|
|
var w = 0;
|
|
|
|
var lastSpace = -1;
|
|
|
|
var prevCharCode = null;
|
|
|
|
var maxWidth = (this._maxWidth > 0) ? this._maxWidth : null;
|
|
|
|
var chars = [];
|
|
|
|
|
|
|
|
// Let's scan the text and work out if any of the lines are > maxWidth
|
|
|
|
for (var i = 0; i < text.length; i++)
|
|
|
|
{
|
|
|
|
var end = (i === text.length - 1) ? true : false;
|
|
|
|
|
|
|
|
if (/(?:\r\n|\r|\n)/.test(text.charAt(i)))
|
|
|
|
{
|
|
|
|
return { width: w, text: text.substr(0, i), end: end, chars: chars };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-03 03:55:15 +00:00
|
|
|
var charCode = text.charCodeAt(i);
|
|
|
|
var charData = data.chars[charCode];
|
|
|
|
|
|
|
|
var c = 0;
|
|
|
|
|
|
|
|
if (!charData)
|
|
|
|
{
|
2015-06-03 04:28:07 +00:00
|
|
|
// Skip a character not found in the font data
|
2015-06-03 03:55:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:23:22 +00:00
|
|
|
// Adjust for kerning from previous character to this one
|
|
|
|
var kerning = (prevCharCode && charData.kerning[prevCharCode]) ? charData.kerning[prevCharCode] : 0;
|
|
|
|
|
|
|
|
// Record the last space in the string
|
|
|
|
lastSpace = /(\s)/.test(text.charAt(i)) ? i : lastSpace;
|
|
|
|
|
|
|
|
// What will the line width be if we add this character to it?
|
|
|
|
c = (kerning + charData.texture.width + charData.xOffset) * scale;
|
|
|
|
|
2015-06-03 03:55:15 +00:00
|
|
|
// Do we need to line-wrap?
|
2015-06-03 04:28:07 +00:00
|
|
|
if (maxWidth && ((w + c) >= maxWidth) && lastSpace > -1)
|
2015-06-03 03:23:22 +00:00
|
|
|
{
|
2015-06-03 03:55:15 +00:00
|
|
|
// The last space was at "lastSpace" which was "i - lastSpace" characters ago
|
|
|
|
return { width: w, text: text.substr(0, i - (i - lastSpace)), end: end, chars: chars };
|
2015-06-03 03:23:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w += charData.xAdvance * scale;
|
|
|
|
|
|
|
|
chars.push(x + (charData.xOffset * scale));
|
|
|
|
|
|
|
|
x += charData.xAdvance * scale;
|
|
|
|
|
|
|
|
prevCharCode = charCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { width: w, text: text, end: end, chars: chars };
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders text and updates it when needed.
|
|
|
|
*
|
|
|
|
* @method Phaser.BitmapText.prototype.updateText
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Phaser.BitmapText.prototype.updateText = function () {
|
|
|
|
|
2015-07-16 00:29:32 +00:00
|
|
|
var data = this._data.font;
|
2015-06-03 03:23:22 +00:00
|
|
|
|
|
|
|
if (!data)
|
2015-03-23 15:03:53 +00:00
|
|
|
{
|
2015-06-03 03:23:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var text = this.text;
|
|
|
|
var scale = this._fontSize / data.size;
|
|
|
|
var lines = [];
|
|
|
|
|
|
|
|
var y = 0;
|
|
|
|
|
|
|
|
this.textWidth = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
var line = this.scanLine(data, scale, text);
|
|
|
|
|
|
|
|
line.y = y;
|
|
|
|
|
|
|
|
lines.push(line);
|
|
|
|
|
|
|
|
if (line.width > this.textWidth)
|
|
|
|
{
|
|
|
|
this.textWidth = line.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
y += (data.lineHeight * scale);
|
|
|
|
|
|
|
|
text = text.substr(line.text.length + 1);
|
|
|
|
|
2015-06-03 12:22:29 +00:00
|
|
|
} while (line.end === false);
|
2015-06-03 03:23:22 +00:00
|
|
|
|
|
|
|
this.textHeight = y;
|
|
|
|
|
|
|
|
var t = 0;
|
|
|
|
var align = 0;
|
|
|
|
var ax = this.textWidth * this.anchor.x;
|
|
|
|
var ay = this.textHeight * this.anchor.y;
|
|
|
|
|
|
|
|
for (var i = 0; i < lines.length; i++)
|
|
|
|
{
|
|
|
|
var line = lines[i];
|
|
|
|
|
|
|
|
if (this._align === 'right')
|
|
|
|
{
|
|
|
|
align = this.textWidth - line.width;
|
|
|
|
}
|
|
|
|
else if (this._align === 'center')
|
|
|
|
{
|
|
|
|
align = (this.textWidth - line.width) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var c = 0; c < line.text.length; c++)
|
|
|
|
{
|
|
|
|
var charCode = line.text.charCodeAt(c);
|
|
|
|
var charData = data.chars[charCode];
|
|
|
|
|
2015-06-16 11:45:26 +00:00
|
|
|
var g = this._glyphs[t];
|
2015-06-03 03:23:22 +00:00
|
|
|
|
|
|
|
if (g)
|
|
|
|
{
|
2015-06-16 11:45:26 +00:00
|
|
|
// Sprite already exists in the glyphs pool, so we'll reuse it for this letter
|
2015-06-03 03:23:22 +00:00
|
|
|
g.texture = charData.texture;
|
2015-06-16 11:45:26 +00:00
|
|
|
// g.name = line.text[c];
|
|
|
|
// console.log('reusing', g.name, 'as', line.text[c]);
|
2015-06-03 03:23:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-16 11:45:26 +00:00
|
|
|
// We need a new sprite as the pool is empty or exhausted
|
2015-06-03 03:23:22 +00:00
|
|
|
g = new PIXI.Sprite(charData.texture);
|
2015-06-16 11:45:26 +00:00
|
|
|
g.name = line.text[c];
|
2015-06-03 03:23:22 +00:00
|
|
|
this._glyphs.push(g);
|
2015-06-16 11:45:26 +00:00
|
|
|
// console.log('new', line.text[c]);
|
2015-06-03 03:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g.position.x = (line.chars[c] + align) - ax;
|
|
|
|
g.position.y = (line.y + (charData.yOffset * scale)) - ay;
|
|
|
|
|
|
|
|
g.scale.set(scale);
|
|
|
|
g.tint = this.tint;
|
|
|
|
|
|
|
|
if (!g.parent)
|
|
|
|
{
|
|
|
|
this.addChild(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove unnecessary children
|
2015-06-16 11:45:26 +00:00
|
|
|
// This moves them from the display list (children array) but retains them in the _glyphs pool
|
2015-06-03 03:23:22 +00:00
|
|
|
for (i = t; i < this._glyphs.length; i++)
|
|
|
|
{
|
|
|
|
this.removeChild(this._glyphs[i]);
|
2015-03-23 15:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-06-03 04:28:07 +00:00
|
|
|
/**
|
|
|
|
* If a BitmapText changes from having a large number of characters to having very few characters it will cause lots of
|
|
|
|
* Sprites to be retained in the BitmapText._glyphs array. Although they are not attached to the display list they
|
|
|
|
* still take up memory while sat in the glyphs pool waiting to be re-used in the future.
|
|
|
|
*
|
|
|
|
* If you know that the BitmapText will not grow any larger then you can purge out the excess glyphs from the pool
|
|
|
|
* by calling this method.
|
|
|
|
*
|
|
|
|
* Calling this doesn't prevent you from increasing the length of the text again in the future.
|
|
|
|
*
|
|
|
|
* @method Phaser.BitmapText.prototype.purgeGlyphs
|
|
|
|
* @return {integer} The amount of glyphs removed from the pool.
|
|
|
|
*/
|
|
|
|
Phaser.BitmapText.prototype.purgeGlyphs = function () {
|
|
|
|
|
|
|
|
var len = this._glyphs.length;
|
|
|
|
var kept = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < this._glyphs.length; i++)
|
|
|
|
{
|
|
|
|
if (this._glyphs[i].parent !== this)
|
|
|
|
{
|
|
|
|
this._glyphs[i].destroy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kept.push(this._glyphs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._glyphs = [];
|
|
|
|
this._glyphs = kept;
|
|
|
|
|
|
|
|
this.updateText();
|
|
|
|
|
|
|
|
return len - kept.length;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-03-23 15:03:53 +00:00
|
|
|
/**
|
2015-06-03 03:23:22 +00:00
|
|
|
* Updates the transform of this object.
|
|
|
|
*
|
|
|
|
* @method Phaser.BitmapText.prototype.updateTransform
|
2015-03-23 15:03:53 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2015-06-03 03:23:22 +00:00
|
|
|
Phaser.BitmapText.prototype.updateTransform = function () {
|
2015-03-23 15:03:53 +00:00
|
|
|
|
2015-06-03 03:23:22 +00:00
|
|
|
if (this.dirty || !this.anchor.equals(this._prevAnchor))
|
|
|
|
{
|
|
|
|
this.updateText();
|
|
|
|
this.dirty = false;
|
|
|
|
this._prevAnchor.copyFrom(this.anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
|
2015-03-23 15:03:53 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-10-17 14:40:44 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-14 03:34:35 +00:00
|
|
|
* @name Phaser.BitmapText#align
|
2015-06-03 03:23:22 +00:00
|
|
|
* @property {string} align - Alignment for multi-line text ('left', 'center' or 'right'), does not affect single lines of text.
|
2014-02-14 03:34:35 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.BitmapText.prototype, 'align', {
|
|
|
|
|
|
|
|
get: function() {
|
2014-02-14 04:34:57 +00:00
|
|
|
return this._align;
|
2014-02-14 03:34:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
|
|
|
|
2015-06-03 03:23:22 +00:00
|
|
|
if (value !== this._align && (value === 'left' || value === 'center' || value === 'right'))
|
2014-02-14 03:34:35 +00:00
|
|
|
{
|
2014-02-14 04:34:57 +00:00
|
|
|
this._align = value;
|
2015-06-03 03:23:22 +00:00
|
|
|
this.updateText();
|
2014-02-14 03:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-02-14 04:34:57 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.BitmapText#tint
|
|
|
|
* @property {number} tint - The tint applied to the BitmapText. This is a hex value. Set to white to disable (0xFFFFFF)
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.BitmapText.prototype, 'tint', {
|
|
|
|
|
|
|
|
get: function() {
|
|
|
|
return this._tint;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
|
|
|
|
|
|
|
if (value !== this._tint)
|
|
|
|
{
|
|
|
|
this._tint = value;
|
2015-06-03 03:23:22 +00:00
|
|
|
this.updateText();
|
2014-02-14 04:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2014-02-14 03:34:35 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-14 03:34:35 +00:00
|
|
|
* @name Phaser.BitmapText#font
|
|
|
|
* @property {string} font - The font the text will be rendered in, i.e. 'Arial'. Must be loaded in the browser before use.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.BitmapText.prototype, 'font', {
|
|
|
|
|
|
|
|
get: function() {
|
|
|
|
return this._font;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
|
|
|
|
|
|
|
if (value !== this._font)
|
|
|
|
{
|
|
|
|
this._font = value.trim();
|
2015-06-03 03:23:22 +00:00
|
|
|
this.updateText();
|
2014-02-14 03:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Phaser.BitmapText#fontSize
|
|
|
|
* @property {number} fontSize - The size of the font in pixels.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
Object.defineProperty(Phaser.BitmapText.prototype, 'fontSize', {
|
2013-09-10 22:51:35 +00:00
|
|
|
|
|
|
|
get: function() {
|
2014-02-14 03:34:35 +00:00
|
|
|
return this._fontSize;
|
2013-09-10 22:51:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
2014-02-14 03:34:35 +00:00
|
|
|
|
2014-03-13 16:49:52 +00:00
|
|
|
value = parseInt(value, 10);
|
2014-02-14 03:34:35 +00:00
|
|
|
|
2015-06-03 04:28:07 +00:00
|
|
|
if (value !== this._fontSize && value > 0)
|
2014-02-14 03:34:35 +00:00
|
|
|
{
|
|
|
|
this._fontSize = value;
|
2015-06-03 03:23:22 +00:00
|
|
|
this.updateText();
|
2014-02-14 03:34:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-14 03:34:35 +00:00
|
|
|
* @name Phaser.BitmapText#text
|
2015-06-03 03:23:22 +00:00
|
|
|
* @property {string} text - The text to be displayed by this BitmapText object.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
Object.defineProperty(Phaser.BitmapText.prototype, 'text', {
|
2013-09-10 22:51:35 +00:00
|
|
|
|
|
|
|
get: function() {
|
2014-02-14 03:34:35 +00:00
|
|
|
return this._text;
|
2013-09-10 22:51:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
2014-02-14 03:34:35 +00:00
|
|
|
|
|
|
|
if (value !== this._text)
|
|
|
|
{
|
2015-06-03 03:23:22 +00:00
|
|
|
this._text = value.toString() || '';
|
|
|
|
this.updateText();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum display width of this BitmapText in pixels.
|
|
|
|
*
|
|
|
|
* If BitmapText.text is longer than maxWidth then the lines will be automatically wrapped
|
|
|
|
* based on the last whitespace character found in the line.
|
|
|
|
*
|
|
|
|
* If no whitespace was found then no wrapping will take place and consequently the maxWidth value will not be honored.
|
|
|
|
*
|
|
|
|
* Disable maxWidth by setting the value to 0.
|
|
|
|
*
|
|
|
|
* @name Phaser.BitmapText#maxWidth
|
|
|
|
* @property {number} maxWidth - The maximum width of this BitmapText in pixels.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.BitmapText.prototype, 'maxWidth', {
|
|
|
|
|
|
|
|
get: function() {
|
|
|
|
|
|
|
|
return this._maxWidth;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
|
|
|
|
|
|
|
if (value !== this._maxWidth)
|
|
|
|
{
|
|
|
|
this._maxWidth = value;
|
|
|
|
this.updateText();
|
2014-02-14 03:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|