@@ -22,8 +22,10 @@ var ParseRetroFont = function (scene, config)
2222{
2323 var w = config . width ;
2424 var h = config . height ;
25+
2526 var cx = Math . floor ( w / 2 ) ;
2627 var cy = Math . floor ( h / 2 ) ;
28+
2729 var letters = GetValue ( config , 'chars' , '' ) ;
2830
2931 if ( letters === '' )
@@ -32,6 +34,13 @@ var ParseRetroFont = function (scene, config)
3234 }
3335
3436 var key = GetValue ( config , 'image' , '' ) ;
37+
38+ var frame = scene . sys . textures . getFrame ( key ) ;
39+ var textureX = frame . cutX ;
40+ var textureY = frame . cutY ;
41+ var textureWidth = frame . source . width ;
42+ var textureHeight = frame . source . height ;
43+
3544 var offsetX = GetValue ( config , 'offset.x' , 0 ) ;
3645 var offsetY = GetValue ( config , 'offset.y' , 0 ) ;
3746 var spacingX = GetValue ( config , 'spacing.x' , 0 ) ;
@@ -42,7 +51,7 @@ var ParseRetroFont = function (scene, config)
4251
4352 if ( charsPerRow === null )
4453 {
45- charsPerRow = scene . sys . textures . getFrame ( key ) . width / w ;
54+ charsPerRow = textureWidth / w ;
4655
4756 if ( charsPerRow > letters . length )
4857 {
@@ -65,10 +74,13 @@ var ParseRetroFont = function (scene, config)
6574
6675 for ( var i = 0 ; i < letters . length ; i ++ )
6776 {
68- // var node = letters[i];
69-
7077 var charCode = letters . charCodeAt ( i ) ;
7178
79+ var u0 = ( textureX + x ) / textureWidth ;
80+ var v0 = ( textureY + y ) / textureHeight ;
81+ var u1 = ( textureX + x + w ) / textureWidth ;
82+ var v1 = ( textureY + y + h ) / textureHeight ;
83+
7284 data . chars [ charCode ] =
7385 {
7486 x : x ,
@@ -81,7 +93,11 @@ var ParseRetroFont = function (scene, config)
8193 yOffset : 0 ,
8294 xAdvance : w ,
8395 data : { } ,
84- kerning : { }
96+ kerning : { } ,
97+ u0 : u0 ,
98+ v0 : v0 ,
99+ u1 : u1 ,
100+ v1 : v1
85101 } ;
86102
87103 r ++ ;
0 commit comments