@@ -32,10 +32,11 @@ function getValue (node, attribute)
3232 * @param {Phaser.Textures.Frame } frame - The texture frame to take into account when creating the uv data.
3333 * @param {integer } [xSpacing=0] - The x-axis spacing to add between each letter.
3434 * @param {integer } [ySpacing=0] - The y-axis spacing to add to the line height.
35+ * @param {Phaser.Textures.Texture } [texture] - If provided, each glyph in the Bitmap Font will be added to this texture as a frame.
3536 *
3637 * @return {Phaser.Types.GameObjects.BitmapText.BitmapFontData } The parsed Bitmap Font data.
3738 */
38- var ParseXMLBitmapFont = function ( xml , frame , xSpacing , ySpacing )
39+ var ParseXMLBitmapFont = function ( xml , frame , xSpacing , ySpacing , texture )
3940{
4041 if ( xSpacing === undefined ) { xSpacing = 0 ; }
4142 if ( ySpacing === undefined ) { ySpacing = 0 ; }
@@ -44,6 +45,7 @@ var ParseXMLBitmapFont = function (xml, frame, xSpacing, ySpacing)
4445 var textureY = frame . cutY ;
4546 var textureWidth = frame . source . width ;
4647 var textureHeight = frame . source . height ;
48+ var sourceIndex = frame . sourceIndex ;
4749
4850 var data = { } ;
4951 var info = xml . getElementsByTagName ( 'info' ) [ 0 ] ;
@@ -69,6 +71,7 @@ var ParseXMLBitmapFont = function (xml, frame, xSpacing, ySpacing)
6971 var node = letters [ i ] ;
7072
7173 var charCode = getValue ( node , 'id' ) ;
74+ var letter = String . fromCharCode ( charCode ) ;
7275 var gx = getValue ( node , 'x' ) ;
7376 var gy = getValue ( node , 'y' ) ;
7477 var gw = getValue ( node , 'width' ) ;
@@ -98,6 +101,11 @@ var ParseXMLBitmapFont = function (xml, frame, xSpacing, ySpacing)
98101 gy -= frame . y ;
99102 }
100103
104+ var u0 = ( textureX + gx ) / textureWidth ;
105+ var v0 = ( textureY + gy ) / textureHeight ;
106+ var u1 = ( textureX + gx + gw ) / textureWidth ;
107+ var v1 = ( textureY + gy + gh ) / textureHeight ;
108+
101109 data . chars [ charCode ] =
102110 {
103111 x : gx ,
@@ -111,11 +119,18 @@ var ParseXMLBitmapFont = function (xml, frame, xSpacing, ySpacing)
111119 xAdvance : getValue ( node , 'xadvance' ) + xSpacing ,
112120 data : { } ,
113121 kerning : { } ,
114- u0 : ( textureX + gx ) / textureWidth ,
115- v0 : ( textureY + gy ) / textureHeight ,
116- u1 : ( textureX + gx + gw ) / textureWidth ,
117- v1 : ( textureY + gy + gh ) / textureHeight
122+ u0 : u0 ,
123+ v0 : v0 ,
124+ u1 : u1 ,
125+ v1 : v1
118126 } ;
127+
128+ if ( texture )
129+ {
130+ var charFrame = texture . add ( letter , sourceIndex , gx , gy , gw , gh ) ;
131+
132+ charFrame . setUVs ( gw , gh , u0 , v0 , u1 , v1 ) ;
133+ }
119134 }
120135
121136 var kernings = xml . getElementsByTagName ( 'kerning' ) ;
0 commit comments