@@ -50,8 +50,8 @@ this.createjs = this.createjs || {};
5050 **/
5151 function BitmapText ( text , spriteSheet ) {
5252 this . Container_constructor ( ) ;
53-
54-
53+
54+
5555 // public properties:
5656 /**
5757 * The text to display.
@@ -60,7 +60,7 @@ this.createjs = this.createjs || {};
6060 * @default ""
6161 **/
6262 this . text = text || "" ;
63-
63+
6464 /**
6565 * A SpriteSheet instance that defines the glyphs for this bitmap text. Each glyph/character
6666 * should have a single frame animation defined in the sprite sheet named the same as
@@ -70,7 +70,7 @@ this.createjs = this.createjs || {};
7070 *
7171 * would indicate that the frame at index 0 of the spritesheet should be drawn for the "A" character. The short form
7272 * is also acceptable:
73- *
73+ *
7474 * "A": 0
7575 *
7676 * Note that if a character in the text is not found in the sprite sheet, it will also
@@ -82,7 +82,7 @@ this.createjs = this.createjs || {};
8282 * @default null
8383 **/
8484 this . spriteSheet = spriteSheet ;
85-
85+
8686 /**
8787 * The height of each line of text. If 0, then it will use a line height calculated
8888 * by checking for the height of the "1", "T", or "L" character (in that order). If
@@ -93,15 +93,15 @@ this.createjs = this.createjs || {};
9393 * @default 0
9494 **/
9595 this . lineHeight = 0 ;
96-
96+
9797 /**
9898 * This spacing (in pixels) will be added after each character in the output.
9999 * @property letterSpacing
100100 * @type Number
101101 * @default 0
102102 **/
103103 this . letterSpacing = 0 ;
104-
104+
105105 /**
106106 * If a space character is not defined in the sprite sheet, then empty pixels equal to
107107 * spaceWidth will be inserted instead. If 0, then it will use a value calculated
@@ -113,8 +113,8 @@ this.createjs = this.createjs || {};
113113 * @default 0
114114 **/
115115 this . spaceWidth = 0 ;
116-
117-
116+
117+
118118 // private properties:
119119 /**
120120 * @property _oldProps
@@ -151,7 +151,7 @@ this.createjs = this.createjs || {};
151151 * @default 100
152152 **/
153153 BitmapText . maxPoolSize = 100 ;
154-
154+
155155 /**
156156 * Sprite object pool.
157157 * @property _spritePool
@@ -161,21 +161,21 @@ this.createjs = this.createjs || {};
161161 */
162162 BitmapText . _spritePool = [ ] ;
163163
164-
164+
165165// public methods:
166166 // Docced in superclass
167167 p . draw = function ( ctx , ignoreCache ) {
168168 if ( this . DisplayObject_draw ( ctx , ignoreCache ) ) { return ; }
169169 this . _updateState ( ) ;
170170 this . Container_draw ( ctx , ignoreCache ) ;
171171 } ;
172-
172+
173173 // Docced in superclass
174174 p . getBounds = function ( ) {
175175 this . _updateText ( ) ;
176176 return this . Container_getBounds ( ) ;
177177 } ;
178-
178+
179179 /**
180180 * Returns true or false indicating whether the display object would be visible if drawn to a canvas.
181181 * This does not account for whether it would be visible within the boundaries of the stage.
@@ -187,11 +187,11 @@ this.createjs = this.createjs || {};
187187 var hasContent = this . cacheCanvas || ( this . spriteSheet && this . spriteSheet . complete && this . text ) ;
188188 return ! ! ( this . visible && this . alpha > 0 && this . scaleX !== 0 && this . scaleY !== 0 && hasContent ) ;
189189 } ;
190-
190+
191191 p . clone = function ( ) {
192192 return this . _cloneProps ( new BitmapText ( this . text , this . spriteSheet ) ) ;
193193 } ;
194-
194+
195195 /**
196196 * <strong>Disabled in BitmapText.</strong>
197197 * @method addChild
@@ -234,7 +234,7 @@ this.createjs = this.createjs || {};
234234 o . spaceWidth = this . spaceWidth ;
235235 return o ;
236236 } ;
237-
237+
238238 /**
239239 * @method _getFrameIndex
240240 * @param {String } character
@@ -250,7 +250,7 @@ this.createjs = this.createjs || {};
250250 }
251251 return o && o . frames [ 0 ] ;
252252 } ;
253-
253+
254254 /**
255255 * @method _getFrame
256256 * @param {String } character
@@ -291,20 +291,20 @@ this.createjs = this.createjs || {};
291291 **/
292292 p . _updateText = function ( ) {
293293 var x = 0 , y = 0 , o = this . _oldProps , change = false , spaceW = this . spaceWidth , lineH = this . lineHeight , ss = this . spriteSheet ;
294- var pool = BitmapText . _spritePool , kids = this . children , childIndex = 0 , numKids = kids . length , sprite ;
295-
294+ var pool = BitmapText . _spritePool , kids = this . children , childIndex = 0 , numKids = kids . length , sprite , spriteBounds ;
295+
296296 for ( var n in o ) {
297297 if ( o [ n ] != this [ n ] ) {
298298 o [ n ] = this [ n ] ;
299299 change = true ;
300300 }
301301 }
302302 if ( ! change ) { return ; }
303-
303+
304304 var hasSpace = ! ! this . _getFrame ( " " , ss ) ;
305305 if ( ! hasSpace && ! spaceW ) { spaceW = this . _getSpaceWidth ( ss ) ; }
306306 if ( ! lineH ) { lineH = this . _getLineHeight ( ss ) ; }
307-
307+
308308 for ( var i = 0 , l = this . text . length ; i < l ; i ++ ) {
309309 var character = this . text . charAt ( i ) ;
310310 if ( character == " " && ! hasSpace ) {
@@ -319,7 +319,7 @@ this.createjs = this.createjs || {};
319319
320320 var index = this . _getFrameIndex ( character , ss ) ;
321321 if ( index == null ) { continue ; }
322-
322+
323323 if ( childIndex < numKids ) {
324324 sprite = kids [ childIndex ] ;
325325 } else {
@@ -329,11 +329,12 @@ this.createjs = this.createjs || {};
329329 }
330330 sprite . spriteSheet = ss ;
331331 sprite . gotoAndStop ( index ) ;
332- sprite . x = x ;
332+ spriteBounds = sprite . getBounds ( ) ;
333+ sprite . x = x - spriteBounds . x ;
333334 sprite . y = y ;
334335 childIndex ++ ;
335-
336- x += sprite . getBounds ( ) . width + this . letterSpacing ;
336+
337+ x += spriteBounds . width + this . letterSpacing ;
337338 }
338339 while ( numKids > childIndex ) {
339340 // faster than removeChild.
0 commit comments