mirror of
https://github.com/photonstorm/phaser
synced 2025-02-25 11:57:19 +00:00
Merge pull request #2277 from slashman/exposeWrappedLinesOnText
Alow precalculating the results of text wrapping.
This commit is contained in:
commit
d4edbe6619
1 changed files with 16 additions and 0 deletions
|
@ -805,6 +805,22 @@ 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) {
|
||||||
|
this.texture.baseTexture.resolution = this._res;
|
||||||
|
this.context.font = this.style.font;
|
||||||
|
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.
|
* Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal bounds.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue