Error loading BitmapText font locally

I am trying this code from Phaser 3 examples…

class Example extends Phaser.Scene
{
    constructor ()
    {
        super();
    }

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

    create ()
    {
        this.dynamic1 = this.add.bitmapText(0, 0, 'desyrel', 'hello world', 60);

    }

    update ()
    {
        this.dynamic1.text = 'Value: boo';
    }
}

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

const game = new Phaser.Game(config);

It works fine but if I try to load the font from my own path with:
this.load.bitmapFont('desyrel', 'fonts/desyrel.png', 'fonts/desyrel.xml');

I get the following error:
Invalid BitmapText key: desyrel
Uncaught TypeError: Cannot read property ‘data’ of undefined

What can be causing it?

Wrong path? Can you see the Preview in the Network Tab?

1 Like

I don’t know if it should bee this way but I realized that I cannot use my own path.

This won’t work:
this.load.bitmapFont('desyrel', 'fonts/desyrel.png', 'fonts/desyrel.xml');

This will:
this.load.bitmapFont('desyrel', 'assets/fonts/bitmap/desyrel.png', 'assets/fonts/bitmap/desyrel.xml');