Phaser 3 doesn't apply font family even when set

120 Views Asked by At

The font itself is applied, but it's not applied initially on load

Is there an event or method in Phaser 3 to check if a font has been loaded? How can I set and apply a font family in Phaser 3?

I'm curious if it's possible to handle it within Phaser 3 without using external libraries.

1

There are 1 best solutions below

0
winner_joiner On

If you don't want to use a library, like a Web Font Loader from google, like shown in this official phaser example, you could simply postpone the creation of the Phaser.Game Object until the styles are loaded, the load event of the window should do, if this is not too late for you.

Something like:

window.addEventListener('load', () => new Phaser.Game(config));

Or in that event call a function, that inturn calls a function on the current running Phaser Scene, that tells the game the font is ready.

Or alternatively you could use phaser's bitmap fonts, you just would have to load them on preload (link to a official example)