Ahoi guys,
I am sorry if this has been already asked, but I haven’t found anything yet to this problem.
So can I set a default font-family in Phaser3, so I don’t have to set it every time I create a new text object?
Cheers
Ahoi guys,
I am sorry if this has been already asked, but I haven’t found anything yet to this problem.
So can I set a default font-family in Phaser3, so I don’t have to set it every time I create a new text object?
Cheers
Unfortunately, no. The default font family is hardcoded to Courier.
Thank you for your quick reply
So I guess this calls for a PR. Let’s see if I find the time to do this any time soon!
My appologies for raising an old thread but I had the same issue today with hundreds of existing text instances all needing to have a custom fontFamily. If anyone else has this issue I have a dirty hack to set a global fontFamily:
create a class:
export class CustomText extends Phaser.GameObjects.Text {
constructor (scene, x, y, text, style){
if(!style) style = {};
if(!style.fontFamily) style.fontFamily = “myCustomFont, Courier”;
super(scene, x, y, text, style);
}
}
And then at the start of you project include:
Phaser.GameObjects.Text = CustomText;
If you are using the scene.add.text(…) you will also need to add:
Phaser.GameObjects.GameObjectFactory.remove(‘text’);
Phaser.GameObjects.GameObjectFactory.register(‘text’, function (x, y, text, style){
return this.displayList.add(new Phaser.GameObjects.Text(this.scene, x, y, text, style));
});
Obviously you will need to change the “myCustomFont” to your font name and if its not a safe font you will have to load that font in your CSS.
If you only have a small amount of text its much better to add the fontFamily manually to each text instance, but if you find yourself in my situation this might save you some time.