How to Change Fonts?



  • I am obviously very new to HaxeFlixel, and this may seem like a dumb question, but here goes:

    How can I format my FlxTexts to be displayed in another font than the default one?

    What I got from the API documention is that one method to change the font is setFormat(). Unfortunately, I just could not get it to work. What is the proper Syntax for this function? And how would I go about using a custom font?

    Any Hints are appreciated.



  • You need to have your custom font somewhere in the assets folder.
    Then you simply use:
    text = new FlxText(100, 100);
    text.setFormat(AssetPaths.Verdana__ttf);
    or
    text.setFormat("assets/fonts/Verdana.ttf");
    if you want to retrieve it manually from where you put it.



  • Thanks a lot. Is there a set of supported fonts by default or do I need to add all fonts into the assets folder manually?



  • There are only two default fonts: FlxAssets.FONT_DEBUGGER and FlxAssets.FONT_DEFAULT.
    You need to add the fonts you want to use yourself.



  • This answers all my questions. Thanks again.


  • administrators

    You can actually also use system fonts:



  • Cool, didn't know that :)
    But I prefer my fonts to be with my projects because I often edit them to gain space.



  • How to use the systems default font to display diffrent text? If dont set text.setFormat(), flixel will use the Flx assets font.



  • @meishijie One possibility is to create a factory class that allows you to generate FlxText objects with the correct font.


  • administrators

    @meishijie One possibility is to create a factory class that allows you to generate FlxText objects with the correct font.

    You can also change the value of FlxAssets.FONT_DEFAULT.


Log in to reply