Skip to content

Commit f331697

Browse files
committed
Text.splitRegExp is a new property that allows you to control the regular expression that is used to split the text into multiple lines (@dai-shi phaserjs#1403)
1 parent feb1b98 commit f331697

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
320320
* Weapon.fireMany attempts to fire multiple bullets from the positions defined in the given array. If you provide a `from` argument, or if there is a tracked Sprite or Pointer, then the positions are treated as __offsets__ from the given objects position. If `from` is undefined, and there is no tracked object, then the bullets are fired from the given positions, as they exist in the world.
321321
* When loading a Sprite Sheet you can now specify the number of frames to skip, as the frames are extracted from the sheet and converted to Frames (thanks @arefiev #2763)
322322
* Math.random returns a random float in the range given (thanks @JTronLabs #2760)
323+
* Text.splitRegExp is a new property that allows you to control the regular expression that is used to split the text into multiple lines (thanks @dai-shi #1403)
323324

324325
### Updates
325326

src/gameobjects/Text.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ Phaser.Text = function (game, x, y, text, style) {
131131
*/
132132
this.useAdvancedWrap = false;
133133

134+
/**
135+
* The Regular Expression that is used to split the text up into lines, in
136+
* multi-line text. By default this is `/(?:\r\n|\r|\n)/`.
137+
* You can change this RegExp to be anything else that you may need.
138+
* @property {Object} splitRegExp
139+
*/
140+
this.splitRegExp = /(?:\r\n|\r|\n)/;
141+
134142
/**
135143
* @property {number} _res - Internal canvas resolution var.
136144
* @private
@@ -354,7 +362,7 @@ Phaser.Text.prototype.setStyle = function (style, update) {
354362
};
355363

356364
/**
357-
* Renders text. This replaces the Pixi.Text.updateText function as we need a few extra bits in here.
365+
* Renders text to the internal canvas.
358366
*
359367
* @method Phaser.Text#updateText
360368
* @private
@@ -373,7 +381,7 @@ Phaser.Text.prototype.updateText = function () {
373381
}
374382

375383
// Split text into lines
376-
var lines = outputText.split(/(?:\r\n|\r|\n)/);
384+
var lines = outputText.split(this.splitRegExp);
377385

378386
// Calculate text width
379387
var tabs = this.style.tabs;

typescript/phaser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4928,6 +4928,7 @@ declare module Phaser {
49284928
shadowOffsetX: number;
49294929
shadowOffsetY: number;
49304930
shadowStroke: boolean;
4931+
splitRegExp: any;
49314932
stroke: string;
49324933
strokeColors: string[];
49334934
strokeThickness: number;

0 commit comments

Comments
 (0)