2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-09-16 16:35:08 +00:00
|
|
|
* BitmapText objects work by taking a texture file and an XML file that describes the font layout.
|
2013-11-28 15:57:09 +00:00
|
|
|
*
|
2013-11-01 17:28:09 +00:00
|
|
|
* On Windows you can use the free app BMFont: http://www.angelcode.com/products/bmfont/
|
|
|
|
* On OS X we recommend Glyph Designer: http://www.71squared.com/en/glyphdesigner
|
2014-02-17 17:54:10 +00:00
|
|
|
* For Web there is the great Littera: http://kvazars.com/littera/
|
2013-11-01 17:28:09 +00:00
|
|
|
*
|
2014-09-16 16:35:08 +00:00
|
|
|
* @class Phaser.BitmapText
|
2013-10-01 12:54:29 +00:00
|
|
|
* @constructor
|
2014-09-16 16:35:08 +00:00
|
|
|
* @extends PIXI.BitmapText
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
2013-10-25 14:22:45 +00:00
|
|
|
* @param {number} x - X position of the new bitmapText object.
|
|
|
|
* @param {number} y - Y position of the new bitmapText object.
|
2014-02-14 03:34:35 +00:00
|
|
|
* @param {string} font - The key of the BitmapFont as stored in Game.Cache.
|
2014-02-14 04:34:57 +00:00
|
|
|
* @param {string} [text=''] - The actual text that will be rendered. Can be set later via BitmapText.text.
|
|
|
|
* @param {number} [size=32] - The size the font will be rendered in, in pixels.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
Phaser.BitmapText = function (game, x, y, font, text, size) {
|
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;
|
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
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
*/
|
2014-02-14 04:34:57 +00:00
|
|
|
this._align = 'left';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} _tint - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._tint = 0xFFFFFF;
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2014-02-14 03:34:35 +00:00
|
|
|
PIXI.BitmapText.call(this, text);
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-02-17 06:00:41 +00:00
|
|
|
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-02-17 06:00:41 +00:00
|
|
|
var components = [
|
|
|
|
'Angle',
|
|
|
|
'AutoCull',
|
|
|
|
'Bounds',
|
|
|
|
'Destroy',
|
|
|
|
'FixedToCamera',
|
|
|
|
'InputEnabled',
|
|
|
|
'InWorld',
|
|
|
|
'LifeSpan',
|
|
|
|
'PhysicsBody',
|
|
|
|
'Reset'
|
|
|
|
];
|
2015-02-16 17:22:51 +00:00
|
|
|
|
2015-02-17 06:00:41 +00:00
|
|
|
Phaser.Component.Core.install.call(this, components);
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype);
|
2013-09-10 22:51:35 +00:00
|
|
|
Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
|
|
|
|
|
|
|
|
/**
|
2014-02-20 03:44:44 +00:00
|
|
|
* @method Phaser.BitmapText.prototype.setStyle
|
2014-02-14 06:04:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-02-14 03:34:35 +00:00
|
|
|
Phaser.BitmapText.prototype.setStyle = function() {
|
|
|
|
|
2014-02-14 04:34:57 +00:00
|
|
|
this.style = { align: this._align };
|
2014-02-14 03:34:35 +00:00
|
|
|
this.fontName = this._font;
|
|
|
|
this.fontSize = this._fontSize;
|
|
|
|
this.dirty = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically called by World.preUpdate.
|
|
|
|
* @method Phaser.BitmapText.prototype.preUpdate
|
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-02-17 06:00:41 +00:00
|
|
|
Phaser.Component.InWorld.preUpdate.call(this);
|
|
|
|
Phaser.Component.Core.preUpdate.call(this);
|
2014-02-15 01:27:42 +00:00
|
|
|
|
|
|
|
return true;
|
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
|
|
|
|
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
|
|
|
|
* @property {string} align - Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text.
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
|
2014-02-14 04:34:57 +00:00
|
|
|
if (value !== this._align)
|
2014-02-14 03:34:35 +00:00
|
|
|
{
|
2014-02-14 04:34:57 +00:00
|
|
|
this._align = value;
|
2014-02-14 06:04:29 +00:00
|
|
|
this.setStyle();
|
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;
|
|
|
|
this.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
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-02-08 22:07:36 +00:00
|
|
|
this.fontName = this._font;
|
2014-02-14 03:34:35 +00:00
|
|
|
this.style.font = this._fontSize + "px '" + this._font + "'";
|
|
|
|
this.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
|
|
|
if (value !== this._fontSize)
|
|
|
|
{
|
|
|
|
this._fontSize = value;
|
|
|
|
this.style.font = this._fontSize + "px '" + this._font + "'";
|
|
|
|
this.dirty = true;
|
|
|
|
}
|
|
|
|
|
2013-09-10 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-14 03:34:35 +00:00
|
|
|
* The text string to be displayed by this Text object, taking into account the style settings.
|
|
|
|
* @name Phaser.BitmapText#text
|
|
|
|
* @property {string} text - The text string to be displayed by this Text object, taking into account the style settings.
|
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)
|
|
|
|
{
|
|
|
|
this._text = value.toString() || ' ';
|
|
|
|
this.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|