Using the default pixel font with an openFL TextField

  • I'm using an openFL TextField type INPUT for android target as a workaround so I can get the softkeyboard when it receives focus.

    I found this and I'm doing a similar workaround.

    I have it scale to my game and everything works fine, but I can't get the font to match the default pixel font HF uses. How can I do that?

    I've tried copying the flixel font to assets/fonts/nokiafc22.ttf to use it, but it still uses the system font. If I specify "_sans" I get the sans font no problem, but I'd like to match the HF pixel font.

    Is there a way to do this? Maybe I'm missing something simple here.

  • I figured it out. I needed to use Assets.getFont() and embedFonts = true;

    Here's the code if it helps anyone.

    		var oflScaleX = Lib.current.stage.stageWidth / FlxG.width;
    		var oflScaleY = Lib.current.stage.stageHeight / FlxG.height;
    		var inputText = new TextField();
    		var fontName = Assets.getFont("fonts/nokiafc22.ttf").fontName;
    		inputText.embedFonts = true;
    		inputText.defaultTextFormat = new TextFormat(fontName, textSize * oflScaleY);
    		inputText.type = TextFieldType.INPUT;

    EDIT: You don't need to copy the font to your project assets. You can use on existing FlxText object to get the font.

    inputText.defaultTextFormat = new TextFormat(txtMessage.font, textSize * oflScaleY);

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.