phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Text new line does not work properly with word wrap

Open robinheidrich opened this issue 2 years ago • 0 comments

Version

  • Phaser Version: v3.60.0-beta.9
  • Operating system: Windows 11
  • Browser: Google Chrome 103.0.5060.134

Description

I have an array of messages that I want to display in a text, each in a new line. \n works fine, just not with longer texts that have been modified by word wrapping.

image

As you can see, Test 1 and Test 2 are on the same line as the longer text, despite the \n character.

Test 3 is then displayed again on a new line, as intended.

Example Test Code

The bug can be reproduced by inserting the following code in the Phaser 3 sandbox.

var config = { width: 800, height: 600, scene: { create } };
var game = new Phaser.Game(config);

function create() {
    var messages = ['Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet', 'Test 1', 'Test 2', 'Test 3'];

    var textStyle = {
        wordWrap: { width: 385, useAdvancedWrap: true }
    };

    var text = this.add.text(0, 0, '', textStyle)
    text.setText(messages.join('\n'));
}

Additional Information

This only happens with longer texts that are split into more lines by word wrapping.

robinheidrich avatar Aug 01 '22 15:08 robinheidrich