Phaser 3 - Loading custom fonts from assets

1.7k views Asked by At

I'm trying to figure out how to load fonts in to a phaser scene from local assets or google fonts.

In my game, I load all the assets in the first scene(Preload scene) and I don't want to load anything in my other scene's preload function.

The problem is I have multiple scenes in my game and fonts that are loaded in the first scene but not available in the other scenes.

I tried the webfontloader plugin and also the below example in phaser labs.

How can I load fonts in my Preload Scene and use them in all the other scenes?

Thanks.

1

There are 1 answers

2
石荒人 On

If you want pass the value from preload scene to other scene.

I recommend using object to save it.

This is how I pass the value to next scene.

let instance:globalParameter
class globalParameter {
    get gameData(): any {
        return this._gameData;
    }

    set gameData(value: any) {
        this._gameData = value;
    }
    private _gameData:any;

    constructor() {
    }
}

export default new globalParameter()