mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Changed from a space to '' and added 'replace' argument.
This commit is contained in:
parent
172f972d8c
commit
36d9c8d673
1 changed files with 50 additions and 1 deletions
|
@ -302,6 +302,55 @@ Phaser.BitmapText.prototype.scanLine = function (data, scale, text) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a text string this will scan each character in the string to ensure it exists
|
||||
* in the BitmapText font data. If it doesn't the character is removed, or replaced with the `replace` argument.
|
||||
*
|
||||
* If no font data has been loaded at all this returns an empty string.
|
||||
*
|
||||
* @method Phaser.BitmapText.prototype.cleanText
|
||||
* @param {string} text - The text to parse.
|
||||
* @param {string} [replace=''] - The replacement string for any missing characters.
|
||||
* @return {string} The cleaned text string.
|
||||
*/
|
||||
Phaser.BitmapText.prototype.cleanText = function (text, replace) {
|
||||
|
||||
if (replace === undefined)
|
||||
{
|
||||
replace = '';
|
||||
}
|
||||
|
||||
var data = this._data.font;
|
||||
|
||||
if (!data)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
var output = '';
|
||||
|
||||
for (var i = 0; i < text.length; i++)
|
||||
{
|
||||
if (!/(?:\r\n|\r|\n)/.test(text.charAt(i)))
|
||||
{
|
||||
var charCode = text.charCodeAt(i);
|
||||
var charData = data.chars[charCode];
|
||||
|
||||
if (charData)
|
||||
{
|
||||
output = output.concat(text[i])
|
||||
}
|
||||
else
|
||||
{
|
||||
output = output.concat(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders text and updates it when needed.
|
||||
*
|
||||
|
@ -572,7 +621,7 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'text', {
|
|||
|
||||
if (value !== this._text)
|
||||
{
|
||||
this._text = value.toString() || '';
|
||||
this._text = this.cleanText(value.toString()) || '';
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue