Alow precalculating the results of text wrapping. This may be useful for

example if the developer wants to control pagination, in which case
he may know in advance the total number of lines the text will wrap to,
and then set it on batches.
This commit is contained in:
slash 2016-01-03 16:33:33 -05:00
parent 172f972d8c
commit ef7c2c6275

View file

@ -805,6 +805,20 @@ Phaser.Text.prototype.addFontWeight = function (weight, position) {
};
/**
* Precalculates word wrap for a given text based on the Text object configuration.
*
* It may be useful is the developer wants to control pagination on long pieces of content.
*
* @method Phaser.Text#precalculateWordWrap
* @param {string} text - The text for which the wrapping will be precalculated.
* @return {array} An array of strings with the pieces of wrapped text.
*/
Phaser.Text.prototype.precalculateWordWrap = function (text) {
var wrappedLines = this.runWordWrap(text);
return wrappedLines.split(/(?:\r\n|\r|\n)/);
};
/**
* Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal bounds.
*