Skip to content

Commit b297950

Browse files
committed
Added wordWrapCharCode
1 parent bea6d91 commit b297950

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ var BitmapText = new Class({
190190
*/
191191
this._dirty = false;
192192

193+
/**
194+
* The character code used to detect for word wrapping.
195+
* Defaults to 32 (a space character).
196+
*
197+
* @name Phaser.GameObjects.BitmapText#wordWrapCharCode
198+
* @type {number}
199+
* @since 3.21.0
200+
*/
201+
this.wordWrapCharCode = 32;
202+
193203
this.setTexture(entry.texture, entry.frame);
194204
this.setPosition(x, y);
195205
this.setOrigin(0, 0);
@@ -355,21 +365,18 @@ var BitmapText = new Class({
355365
// global = The BitmapText, taking into account scale and world position
356366
// lines = The BitmapText line data
357367

358-
if (this._dirty)
359-
{
360-
GetBitmapTextSize(this, round, this._bounds);
361-
362-
if (this._bounds.reset)
363-
{
364-
this._bounds.reset = false;
368+
var bounds = this._bounds;
365369

366-
this.updateDisplayOrigin();
367-
}
370+
if (this._dirty || this.scaleX !== bounds.scaleX || this.scaleY !== bounds.scaleY)
371+
{
372+
GetBitmapTextSize(this, round, bounds);
368373

369374
this._dirty = false;
375+
376+
this.updateDisplayOrigin();
370377
}
371378

372-
return this._bounds;
379+
return bounds;
373380
},
374381

375382
/**
@@ -421,19 +428,28 @@ var BitmapText = new Class({
421428
* If no whitespace was found then no wrapping will take place and consequently the `maxWidth` value will not be honored.
422429
*
423430
* Disable maxWidth by setting the value to 0.
431+
*
432+
* You can set the whitespace character to be searched for by setting the `wordWrapCharCode` parameter or property.
424433
*
425434
* @method Phaser.GameObjects.BitmapText#setMaxWidth
426435
* @since 3.21.0
427436
*
428437
* @param {number} value - The maximum display width of this BitmapText in pixels. Set to zero to disable.
438+
* @param {number} [wordWrapCharCode] - The character code to check for when word wrapping. Defaults to 32 (the space character).
429439
*
430440
* @return {this} This BitmapText Object.
431441
*/
432-
setMaxWidth: function (value)
442+
setMaxWidth: function (value, wordWrapCharCode)
433443
{
434444
this._maxWidth = value;
445+
435446
this._dirty = true;
436447

448+
if (wordWrapCharCode !== undefined)
449+
{
450+
this.wordWrapCharCode = wordWrapCharCode;
451+
}
452+
437453
return this;
438454
},
439455

0 commit comments

Comments
 (0)