flixel icon indicating copy to clipboard operation
flixel copied to clipboard

Different position and wrong height using FFF Tusj font

Open IBwWG opened this issue 9 years ago • 7 comments

  • Flixel version: dev (updated now)
  • OpenFL version: 3.6.0
  • Lime version: 2.9.0
  • Affected targets: flash/debug, windows/debug

Code snippet reproducing the issue:

package;

import flixel.FlxState;
import flixel.text.FlxText;

class PlayState extends FlxState
{
    override public function create():Void
    {
        var withDefaultFont:FlxText = cast add(new FlxText(0, 0, 0, "TEST", 300));
        withDefaultFont.setGraphicSize(0, 50);
        withDefaultFont.updateHitbox();
        trace(withDefaultFont.frameHeight, withDefaultFont.height);

        var withFFFTusj:FlxText = cast add(new FlxText(0, 0, 0, "TEST", 300));
        withFFFTusj.font = "assets/fonts/FFF_Tusj.ttf";
        withFFFTusj.setGraphicSize(0, 50);
        withFFFTusj.updateHitbox();
        trace(withFFFTusj.frameHeight, withFFFTusj.height);
    }
}

The above code relies on this font unzipped and renamed with an underscore and put into the assets/fonts folder of the project, but the problem also occurs with the Georgia and Georgia Bold fonts included with Win7.


Observed behavior: The two FlxTexts are in very different locations, and the debug output of the second line is 344,344 (in contrast with the first line, which is 379,50.) Screenshot:

ffftusj-different-pos-and-height

Expected behavior: They should be in the same location, and the debug output of the second line should be similar to the first line (at least, the second number should be roughly 50).

IBwWG avatar Mar 09 '16 08:03 IBwWG

I'm not sure what exactly is causing this yet, but it has to do with the time / order regenGraphic() ends up being called and setting .font. When enabling drawDebug, you'll notice that updateHitbox() doesn't actually update the hitbox here, and a drawFrame() call after setGraphicSize() fixes this issue.

If you change default font and then set .font afterwards in the first example, you'll see the same issue:

FlxAssets.FONT_DEFAULT = "assets/FFF Tusj.ttf";
var withDefaultFont:FlxText = cast add(new FlxText(0, 0, 0, "TEST", 300));
withDefaultFont.font = "Nokia Cellphone FC Small";
withDefaultFont.setGraphicSize(0, 50);
withDefaultFont.updateHitbox();

Gama11 avatar Mar 09 '16 09:03 Gama11

It's funny you bring up FONT_DEFAULT, because that was the method I had been using originally when I first saw this issue. I avoided using it in the example to try to keep it narrower. But you're right, when I use that method in the example (without changing .font) it works correctly. I believe there's another issue then too...I'll try to narrow it down...

IBwWG avatar Mar 09 '16 09:03 IBwWG

Btw, using .scale on FlxText is a bit unusual and leads to bad results (due to scaling down the bitmap, whereas .size would just generate the font graphic at that size).

With .scale:

With .size:

Gama11 avatar Mar 09 '16 09:03 Gama11

Thanks, that's good to know. I'll have to do my calculations a bit differently because I'm tweening the width in my project, not the height, but that should definitely help! (Assuming rerendering the text is as fast as scaling the bitmap.) Update: yes, this looks great and is performant. :)

I figured out what breaks my project, and it's that I was also tweening the colour. You can see that this example is also broken (in terms of debug output, not position):

    override public function create():Void
    {
        FlxAssets.FONT_DEFAULT = "assets/fonts/FFF_Tusj.ttf";

        var withFFFTusj:FlxText = cast add(new FlxText(0, 0, 0, "TEST", 300));
        trace(withFFFTusj.height);
        withFFFTusj.setGraphicSize(200);
        withFFFTusj.updateHitbox();
        withFFFTusj.color = 0xffff0000;
        trace(withFFFTusj.height);
    }

IBwWG avatar Mar 09 '16 09:03 IBwWG

Also I'm not sure about the drawFrame() workaround because in the original context that should be called many times during tweening, right? E.g. this doesn't work (i.e. the position is fine, but the debug output has both numbers equal instead of the second one being ~50):

        FlxAssets.FONT_DEFAULT = "assets/fonts/FFF_Tusj.ttf";
        var withFFFTusj:FlxText = cast add(new FlxText(0, 0, 0, "TEST", 300));
        trace(withFFFTusj.height);
        withFFFTusj.setGraphicSize(200);
        withFFFTusj.updateHitbox();
        withFFFTusj.color = 0xffff0000;
        withFFFTusj.drawFrame(true);
        trace(withFFFTusj.height);

IBwWG avatar Mar 09 '16 10:03 IBwWG

Huh, I just had this on windows/debug (wrong height) vs flash/debug, with Georgia Bold, on flixel 4.1.1. The height came out way higher than it should've been, in the hundreds instead of < 100.

IBwWG avatar Aug 23 '16 13:08 IBwWG

Still reproduces.

Gama11 avatar Apr 22 '18 19:04 Gama11