mirror of
https://github.com/wassname/phaser.git
synced 2026-08-05 13:21:00 +08:00
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:
@@ -20,8 +20,8 @@
|
||||
* @param {number} x - X position of the new bitmapText object.
|
||||
* @param {number} y - Y position of the new bitmapText object.
|
||||
* @param {string} font - The key of the BitmapFont as stored in Game.Cache.
|
||||
* @param {string} [text] - The actual text that will be rendered. Can be set later via BitmapText.text.
|
||||
* @param {number} [size] - The size the font will be rendered in, in pixels.
|
||||
* @param {string} [text=''] - The actual text that will be rendered. Can be set later via BitmapText.text.
|
||||
* @param {number} [size=32] - The size the font will be rendered in, in pixels.
|
||||
*/
|
||||
Phaser.BitmapText = function (game, x, y, font, text, size) {
|
||||
|
||||
@@ -85,10 +85,16 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
|
||||
this._fontSize = size;
|
||||
|
||||
/**
|
||||
* @property {number} lineSpacing - Additional spacing (in pixels) between each line of text if multi-line.
|
||||
* @property {string} _align - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._lineSpacing = 0;
|
||||
this._align = 'left';
|
||||
|
||||
/**
|
||||
* @property {number} _tint - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._tint = 0xFFFFFF;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Events} events - The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
|
||||
@@ -119,19 +125,10 @@ Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
|
||||
*/
|
||||
Phaser.BitmapText.prototype.setStyle = function() {
|
||||
|
||||
// style = style || {};
|
||||
// style.align = style.align || 'left';
|
||||
this.style = { align: 'left' };
|
||||
|
||||
this.style = { align: this._align };
|
||||
this.fontName = this._font;
|
||||
this.fontSize = this._fontSize;
|
||||
|
||||
// var font = style.font.split(' ');
|
||||
// this.fontName = font[font.length - 1];
|
||||
// this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size;
|
||||
|
||||
this.dirty = true;
|
||||
// this.tint = style.tint;
|
||||
|
||||
};
|
||||
|
||||
@@ -182,16 +179,6 @@ Phaser.BitmapText.prototype.postUpdate = function () {
|
||||
*/
|
||||
Phaser.BitmapText.prototype.destroy = function() {
|
||||
|
||||
if (this.canvas && this.canvas.parentNode)
|
||||
{
|
||||
this.canvas.parentNode.removeChild(this.canvas);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.canvas = null;
|
||||
this.context = null;
|
||||
}
|
||||
|
||||
if (this.filters)
|
||||
{
|
||||
this.filters = null;
|
||||
@@ -202,23 +189,20 @@ Phaser.BitmapText.prototype.destroy = function() {
|
||||
this.parent.remove(this);
|
||||
}
|
||||
|
||||
this.texture.destroy();
|
||||
|
||||
if (this.canvas.parentNode)
|
||||
{
|
||||
this.canvas.parentNode.removeChild(this.canvas);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.canvas = null;
|
||||
this.context = null;
|
||||
}
|
||||
|
||||
this.exists = false;
|
||||
this.visible = false;
|
||||
|
||||
this.game = null;
|
||||
|
||||
if (this.children.length > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
this.removeChild(this.children[0]);
|
||||
}
|
||||
while (this.children.length > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,14 +212,14 @@ Phaser.BitmapText.prototype.destroy = function() {
|
||||
Object.defineProperty(Phaser.BitmapText.prototype, 'align', {
|
||||
|
||||
get: function() {
|
||||
return this.style.align;
|
||||
return this._align;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value !== this.style.align)
|
||||
if (value !== this._align)
|
||||
{
|
||||
this.style.align = value;
|
||||
this._align = value;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
@@ -243,6 +227,27 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'align', {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.BitmapText#tint
|
||||
* @property {number} tint - The tint applied to the BitmapText. This is a hex value. Set to white to disable (0xFFFFFF)
|
||||
*/
|
||||
Object.defineProperty(Phaser.BitmapText.prototype, 'tint', {
|
||||
|
||||
get: function() {
|
||||
return this._tint;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value !== this._tint)
|
||||
{
|
||||
this._tint = value;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Indicates the rotation of the Text, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
|
||||
|
||||
+5
-4
@@ -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);
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -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')
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user