Skip to content

GameObjects.BitmapText.setFont -> setFont function ignores arguments when the texture doesnt changes #6740

@AlvaroNeuronup

Description

@AlvaroNeuronup

Version

  • Phaser Version: 3.70.0

Description

Setting font on a BitmapText without changing the texture doesnt check the new font-size and ignores it.
Also ignores the align argument.

Expected behaviour

setFont('same-texture', 48);

should work the same as:

setFont('same-texture').setFontSize(48); // This works fine

Example Test Code

class Example extends Phaser.Scene {

    preload() {
        this.load.bitmapFont('desyrel', 'assets/fonts/bitmap/desyrel.png', 'assets/fonts/bitmap/desyrel.xml');
        this.load.bitmapFont('desyrel-pink', 'assets/fonts/bitmap/desyrel-pink.png', 'assets/fonts/bitmap/desyrel-pink.xml');
        this.load.bitmapFont('shortStack', 'assets/fonts/bitmap/shortStack.png', 'assets/fonts/bitmap/shortStack.xml');
    }

    create() {
        const b2 = this.add.bitmapText(400, 400, 'desyrel', 'Phaser test', 40);

        b2.setFont('desyrel', 12);
        console.warn(b2.fontSize); // It should be 12 but it is 40 

        // If the font changes it works fine
        // b2.setFont('shortStack', 12);
        // console.warn(b2.fontSize);
    }
}

const config = {
    type: Phaser.WEBGL,
    parent: 'phaser-example',
    scene: Example
};

const game = new Phaser.Game(config);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions