mirror of
https://github.com/wassname/phaser.git
synced 2026-07-24 13:10:53 +08:00
BitmapFont fixes and updates and Cache support for it added. Working sweet now.
This commit is contained in:
@@ -462,12 +462,11 @@ Phaser.BitmapFont.prototype.pasteLine = function (line, x, y, customSpacingX) {
|
||||
else
|
||||
{
|
||||
// If the character doesn't exist in the font then we don't want a blank space, we just want to skip it
|
||||
if (this.grabData[line.charCodeAt(c)])
|
||||
if (this.grabData[line.charCodeAt(c)] >= 0)
|
||||
{
|
||||
this.stamp.frame = this.grabData[line.charCodeAt(c)];
|
||||
p.set(x, y);
|
||||
this.render(this.stamp, p, false);
|
||||
// this.bmd.copyPixels(this.fontSet, this.grabData[line.charCodeAt(c)], x, y);
|
||||
|
||||
x += this.characterWidth + this.customSpacingX;
|
||||
|
||||
@@ -522,9 +521,12 @@ Phaser.BitmapFont.prototype.removeUnsupportedCharacters = function (stripCR) {
|
||||
|
||||
for (var c = 0; c < this._text.length; c++)
|
||||
{
|
||||
if (this.grabData[this._text.charCodeAt(c)] || this._text.charCodeAt(c) == 32 || (!stripCR && this._text.charAt(c) === "\n"))
|
||||
var char = this._text[c];
|
||||
var code = char.charCodeAt(0);
|
||||
|
||||
if (this.grabData[code] >= 0 || (!stripCR && char === "\n"))
|
||||
{
|
||||
newString = newString.concat(this._text.charAt(c));
|
||||
newString = newString.concat(char);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -258,9 +258,12 @@ Phaser.GameObjectFactory.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new BitmapFont object.
|
||||
* Create a new BitmapFont object to be used as a texture for an Image or Sprite and optionally add it to the Cache.
|
||||
* The texture can be asssigned or one or multiple images/sprites, but note that the text the BitmapFont uses will be shared across them all,
|
||||
* i.e. if you need each Image to have different text in it, then you need to create multiple BitmapFont objects.
|
||||
*
|
||||
* @param {string} font - The key of the BitmapFont as stored in Game.Cache.
|
||||
* @method Phaser.GameObjectFactory#bitmapFont
|
||||
* @param {string} font - The key of the image in the Game.Cache that the BitmapFont will use.
|
||||
* @param {number} characterWidth - The width of each character in the font set.
|
||||
* @param {number} characterHeight - The height of each character in the font set.
|
||||
* @param {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
|
||||
|
||||
@@ -67,6 +67,12 @@ Phaser.Cache = function (game) {
|
||||
*/
|
||||
this._bitmapDatas = {};
|
||||
|
||||
/**
|
||||
* @property {object} _bitmapFont - BitmapFont key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._bitmapFont = {};
|
||||
|
||||
this.addDefaultImage();
|
||||
this.addMissingImage();
|
||||
|
||||
@@ -134,6 +140,19 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a Phaser.BitmapFont in to the cache.
|
||||
*
|
||||
* @method Phaser.Cache#addBitmapFont
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
* @param {Phaser.BitmapFont} texture - The BitmapFont object to be stored. This can be applied to any Image/Sprite as a texture.
|
||||
*/
|
||||
addBitmapFont: function (key, texture) {
|
||||
|
||||
this._bitmapFont[key] = texture;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new sprite sheet in to the cache.
|
||||
*
|
||||
@@ -450,6 +469,26 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a BitmapFont object from the cache by its key.
|
||||
*
|
||||
* @method Phaser.Cache#getBitmapFont
|
||||
* @param {string} key - Asset key of the BitmapFont object to retrieve from the Cache.
|
||||
* @return {Phaser.BitmapFont} The requested BitmapFont object if found, or null if not.
|
||||
*/
|
||||
getBitmapFont: function (key) {
|
||||
|
||||
if (this._bitmapFont[key])
|
||||
{
|
||||
return this._bitmapFont[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getBitmapFont: Invalid key: "' + key + '"');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if an image key exists.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user