55*/
66
77/**
8- * BitmapText objects work by taking a texture file and an XML file that describes the font layout.
8+ * BitmapText objects work by taking a texture file and an XML file that describes the font structure.
9+ * It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to
10+ * match the font structure.
11+ *
12+ * BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability
13+ * to use Web Fonts, however you trade this flexibility for rendering speed. You can also create visually compelling BitmapTexts by
14+ * processing the font texture in an image editor, applying fills and any other effects required.
915*
10- * On Windows you can use the free app BMFont: http://www.angelcode.com/products/bmfont/
11- * On OS X we recommend Glyph Designer: http://www.71squared.com/en/glyphdesigner
12- * For Web there is the great Littera: http://kvazars.com/littera/
16+ * To create a BitmapText you can use:
17+ *
18+ * BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
19+ * Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
20+ * Littera (Web-based, free): http://kvazars.com/littera/
1321*
1422* @class Phaser.BitmapText
1523* @constructor
@@ -46,6 +54,12 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
4654 */
4755 this . type = Phaser . BITMAPTEXT ;
4856
57+ /**
58+ * @property {number } physicsType - The const physics body type of this object.
59+ * @readonly
60+ */
61+ this . physicsType = Phaser . SPRITE ;
62+
4963 /**
5064 * @property {string } _text - Internal cache var.
5165 * @private
@@ -76,6 +90,18 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
7690 */
7791 this . _tint = 0xFFFFFF ;
7892
93+ /**
94+ * @property {number } _tw - Internal cache var. Holds the previous textWidth.
95+ * @private
96+ */
97+ this . _tw = 0 ;
98+
99+ /**
100+ * @property {number } _th - Internal cache var. Holds the previous textHeight.
101+ * @private
102+ */
103+ this . _th = 0 ;
104+
79105 PIXI . BitmapText . call ( this , text ) ;
80106
81107 Phaser . Component . Core . init . call ( this , game , x , y , '' , null ) ;
@@ -85,7 +111,7 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
85111Phaser . BitmapText . prototype = Object . create ( PIXI . BitmapText . prototype ) ;
86112Phaser . BitmapText . prototype . constructor = Phaser . BitmapText ;
87113
88- var components = [
114+ Phaser . Component . Core . install . call ( Phaser . BitmapText . prototype , [
89115 'Angle' ,
90116 'AutoCull' ,
91117 'Bounds' ,
@@ -96,33 +122,28 @@ var components = [
96122 'LifeSpan' ,
97123 'PhysicsBody' ,
98124 'Reset'
99- ] ;
125+ ] ) ;
100126
101- Phaser . Component . Core . install . call ( Phaser . BitmapText . prototype , components ) ;
102-
103- /**
104- * @method Phaser.BitmapText.prototype.setStyle
105- * @private
106- */
107- Phaser . BitmapText . prototype . setStyle = function ( ) {
108-
109- this . style = { align : this . _align } ;
110- this . fontName = this . _font ;
111- this . fontSize = this . _fontSize ;
112- this . dirty = true ;
113-
114- } ;
127+ Phaser . BitmapText . prototype . preUpdatePhysics = Phaser . Component . PhysicsBody . preUpdate ;
128+ Phaser . BitmapText . prototype . preUpdateLifeSpan = Phaser . Component . LifeSpan . preUpdate ;
129+ Phaser . BitmapText . prototype . preUpdateInWorld = Phaser . Component . InWorld . preUpdate ;
130+ Phaser . BitmapText . prototype . preUpdateCore = Phaser . Component . Core . preUpdate ;
115131
116132/**
117133* Automatically called by World.preUpdate.
118- * @method Phaser.BitmapText.prototype.preUpdate
134+ *
135+ * @method
136+ * @memberof Phaser.BitmapText
137+ * @return {boolean } True if the BitmapText was rendered, otherwise false.
119138*/
120139Phaser . BitmapText . prototype . preUpdate = function ( ) {
121140
122- Phaser . Component . InWorld . preUpdate . call ( this ) ;
123- Phaser . Component . Core . preUpdate . call ( this ) ;
141+ if ( ! this . preUpdatePhysics ( ) || ! this . preUpdateLifeSpan ( ) || ! this . preUpdateInWorld ( ) )
142+ {
143+ return false ;
144+ }
124145
125- return true ;
146+ return this . preUpdateCore ( ) ;
126147
127148} ;
128149
@@ -135,6 +156,26 @@ Phaser.BitmapText.prototype.postUpdate = function () {
135156 Phaser . Component . PhysicsBody . postUpdate . call ( this ) ;
136157 Phaser . Component . FixedToCamera . postUpdate . call ( this ) ;
137158
159+ if ( this . body && ( ( this . textWidth !== this . _tw ) || ( this . textHeight !== this . _th ) ) )
160+ {
161+ this . body . setSize ( this . textWidth , this . textHeight ) ;
162+ this . _tw = this . textWidth ;
163+ this . _th = this . textHeight ;
164+ }
165+
166+ } ;
167+
168+ /**
169+ * @method Phaser.BitmapText.prototype.setStyle
170+ * @private
171+ */
172+ Phaser . BitmapText . prototype . setStyle = function ( ) {
173+
174+ this . style = { align : this . _align } ;
175+ this . fontName = this . _font ;
176+ this . fontSize = this . _fontSize ;
177+ this . dirty = true ;
178+
138179} ;
139180
140181/**
0 commit comments