Improving JSON BitmapText implementation

This commit is contained in:
Charlo 2015-07-16 13:30:55 +02:00
parent f552615982
commit 795a7c80a8
2 changed files with 12 additions and 7 deletions

View file

@ -24,7 +24,8 @@
* Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner * Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
* Littera (Web-based, free): http://kvazars.com/littera/ * Littera (Web-based, free): http://kvazars.com/littera/
* *
* For most use cases it is recommended to use XML. If you wish to use JSON, the formatting should be equal to the result of running a valid XML file through the popular X2JS library. * For most use cases it is recommended to use XML. If you wish to use JSON, the formatting should be equal to the result of
* converting a valid XML file through the popular X2JS library. An online tool for conversion can be found here: http://codebeautify.org/xmltojson
* *
* @class Phaser.BitmapText * @class Phaser.BitmapText
* @constructor * @constructor

View file

@ -94,7 +94,7 @@ Phaser.LoaderParser = {
jsonBitmapFont: function (json, baseTexture, xSpacing, ySpacing) { jsonBitmapFont: function (json, baseTexture, xSpacing, ySpacing) {
var data = { var data = {
font: json.font.info._font, font: json.font.info._face,
size: parseInt(json.font.info._size, 10), size: parseInt(json.font.info._size, 10),
lineHeight: parseInt(json.font.common._lineHeight, 10) + ySpacing, lineHeight: parseInt(json.font.common._lineHeight, 10) + ySpacing,
chars: {} chars: {}
@ -120,15 +120,19 @@ Phaser.LoaderParser = {
); );
json.font.kernings.kerning.forEach( if (json.font.kernings && json.font.kernings.kerning) {
function parseKerning(kerning) { json.font.kernings.kerning.forEach(
data.chars[kerning._second].kerning[kerning._first] = parseInt(kerning._amount, 10); function parseKerning(kerning) {
} data.chars[kerning._second].kerning[kerning._first] = parseInt(kerning._amount, 10);
); }
);
}
return this.finalizeBitmapFont(baseTexture, data); return this.finalizeBitmapFont(baseTexture, data);