Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitmapText setMaxWidth() bug #6807

Closed
AlvaroNeuronup opened this issue Apr 30, 2024 · 3 comments · May be fixed by jonesrussell/nishman#6
Closed

BitmapText setMaxWidth() bug #6807

AlvaroNeuronup opened this issue Apr 30, 2024 · 3 comments · May be fixed by jonesrussell/nishman#6
Assignees

Comments

@AlvaroNeuronup
Copy link

Version

  • Phaser Version: 3.80.1
  • Operating system: Windows 11
  • Browser: Chrome, Edge

Description

When using a BitmapText with setMaxWidth if the max width is less than one of the word's width it creates additional empty lines changing the object's height. This does not happen with text game object.

Example Test Code

class MainScene extends Phaser.Scene {

    constructor() {
        super({ key: "MainScene" });
    }

    preload() {
        this.load.bitmapFont('gothic', 'https://labs.phaser.io/assets/fonts/bitmap/gothic.png', 'https://labs.phaser.io/assets/fonts/bitmap/gothic.xml');
    }

    create() {
        // Text
        const text = this.add.text(100, 100, 'Hello Phaser', { fontFamily: 'Arial Black', fontSize: 32 });
        text.style.setWordWrapWidth(30);
        // Rectangle matches with game object size
        this.add.rectangle(text.x, text.y, text.width, text.height, 0xff00ff, 0.3).setOrigin(0);

        // Bitmap Text 
        const bitmapText = this.add.bitmapText(100, 400, 'gothic', 'Hello Phaser', 32);
        bitmapText.setMaxWidth(30);
        // Rectangle shows the extra empty line
        this.add.rectangle(bitmapText.x, bitmapText.y, bitmapText.width, bitmapText.height, 0xff00ff, 0.3).setOrigin(0);
    }
}

const game = new Phaser.Game({
    type: Phaser.AUTO,
    width: 800,
    height: 800,
    backgroundColor: '#111111',
    scale: {
        mode: Phaser.Scale.FIT,
        autoCenter: Phaser.Scale.CENTER_BOTH
    },
    scene: [MainScene]
})

Test screenshot

Bug screenshot

The BitmapText (bottom) has 3 lines, should have only 2 like the text on the top.

Expected behaviour

Bitmap text should not add additional empty lines even if its text cant fit with the given max width.

@zekeatchan
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

@AlvaroNeuronup
Copy link
Author

The issue was solved in Beta 3.85.0-1 but is back in Beta 3.85.0-2

@zekeatchan
Copy link
Collaborator

zekeatchan commented Jul 30, 2024

Hi @AlvaroNeuronup, fixed the bug where an extra line spacing is added before the first word because it exceeded the maxWidth. Kindly test it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants