Loader.bitmapFont now has 2 extra parameters: xSpacing and ySpacing. These allow you to add extra spacing to each letter or line of the font.

This commit is contained in:
photonstorm
2014-02-14 04:34:57 +00:00
parent 24f2e2a46d
commit b38b00c2c1
6 changed files with 75 additions and 62 deletions
+5 -4
View File
@@ -212,17 +212,18 @@ Phaser.Cache.prototype = {
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this font xml file.
* @param {object} data - Extra font data.
* @param xmlData {object} Texture atlas frames data.
* @param {object} xmlData - Texture atlas frames data.
* @param {number} [xSpacing=0] - If you'd like to add additional horizontal spacing between the characters then set the pixel value here.
* @param {number} [ySpacing=0] - If you'd like to add additional vertical spacing between the lines then set the pixel value here.
*/
addBitmapFont: function (key, url, data, xmlData) {
addBitmapFont: function (key, url, data, xmlData, xSpacing, ySpacing) {
this._images[key] = { url: url, data: data, spriteSheet: true };
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
Phaser.LoaderParser.bitmapFont(this.game, xmlData, key);
// this._images[key].frameData = Phaser.AnimationParser.XMLData(this.game, xmlData, key);
Phaser.LoaderParser.bitmapFont(this.game, xmlData, key, xSpacing, ySpacing);
},
+9 -5
View File
@@ -497,17 +497,21 @@ Phaser.Loader.prototype = {
* @param {string} textureURL - The url of the font image file.
* @param {string} [xmlURL] - The url of the font data file (xml/fnt)
* @param {object} [xmlData] - An optional XML data object.
* @param {number} [xSpacing=0] - If you'd like to add additional horizontal spacing between the characters then set the pixel value here.
* @param {number} [ySpacing=0] - If you'd like to add additional vertical spacing between the lines then set the pixel value here.
* @return {Phaser.Loader} This Loader instance.
*/
bitmapFont: function (key, textureURL, xmlURL, xmlData) {
bitmapFont: function (key, textureURL, xmlURL, xmlData, xSpacing, ySpacing) {
if (typeof xmlURL === "undefined") { xmlURL = null; }
if (typeof xmlData === "undefined") { xmlData = null; }
if (typeof xSpacing === "undefined") { xSpacing = 0; }
if (typeof ySpacing === "undefined") { ySpacing = 0; }
// A URL to a json/xml file has been given
if (xmlURL)
{
this.addToFileList('bitmapfont', key, textureURL, { xmlURL: xmlURL });
this.addToFileList('bitmapfont', key, textureURL, { xmlURL: xmlURL, xSpacing: xSpacing, ySpacing: ySpacing });
}
else
{
@@ -540,7 +544,7 @@ Phaser.Loader.prototype = {
}
else
{
this.addToFileList('bitmapfont', key, textureURL, { xmlURL: null, xmlData: xml });
this.addToFileList('bitmapfont', key, textureURL, { xmlURL: null, xmlData: xml, xSpacing: xSpacing, ySpacing: ySpacing });
}
}
}
@@ -1005,7 +1009,7 @@ Phaser.Loader.prototype = {
if (file.xmlURL == null)
{
this.game.cache.addBitmapFont(file.key, file.url, file.data, file.xmlData);
this.game.cache.addBitmapFont(file.key, file.url, file.data, file.xmlData, file.xSpacing, file.ySpacing);
}
else
{
@@ -1208,7 +1212,7 @@ Phaser.Loader.prototype = {
if (file.type == 'bitmapfont')
{
this.game.cache.addBitmapFont(file.key, file.url, file.data, xml);
this.game.cache.addBitmapFont(file.key, file.url, file.data, xml, file.xSpacing, file.ySpacing);
}
else if (file.type == 'textureatlas')
{
+5 -5
View File
@@ -10,15 +10,15 @@
* @class Phaser.LoaderParser
*/
Phaser.LoaderParser = {
/**
* Parse frame data from an XML file.
* Parse a Bitmap Font from an XML file.
* @method Phaser.LoaderParser.bitmapFont
* @param {Phaser.Game} game - A reference to the current game.
* @param {object} xml - XML data you want to parse.
* @param {string} cacheKey - The key of the texture this font uses in the cache.
*/
bitmapFont: function (game, xml, cacheKey) {
bitmapFont: function (game, xml, cacheKey, xSpacing, ySpacing) {
if (!xml || /MSIE 9/i.test(navigator.userAgent) || navigator.isCocoonJS)
{
@@ -41,7 +41,7 @@ Phaser.LoaderParser = {
data.font = info.getAttribute('face');
data.size = parseInt(info.getAttribute('size'), 10);
data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10);
data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10) + ySpacing;
data.chars = {};
var letters = xml.getElementsByTagName('char');
@@ -61,7 +61,7 @@ Phaser.LoaderParser = {
data.chars[charCode] = {
xOffset: parseInt(letters[i].getAttribute('xoffset'), 10),
yOffset: parseInt(letters[i].getAttribute('yoffset'), 10),
xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10),
xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10) + xSpacing,
kerning: {},
texture: PIXI.TextureCache[cacheKey] = new PIXI.Texture(texture, textureRect)
};