-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for all BMFont output file types in FlxBitmapFont #2949
Conversation
are there additional features we could gain from these other file formats, or is this just for variety? |
whoops, got distracted, got any sample files I can use to test this, preferably 3 different files formats made from the same font |
Sure, I used this font: https://emhuo.itch.io/nico-pixel-fonts-pack Source code that I used: package;
import flixel.FlxG;
import flixel.FlxState;
import flixel.graphics.frames.FlxBitmapFont;
import flixel.text.FlxBitmapText;
class PlayState extends FlxState
{
var bmText:FlxBitmapText;
var curIndex = 0;
var tests:Array<{ font: FlxBitmapFont, text: String }>;
override public function create()
{
super.create();
var testXMLFont:FlxBitmapFont = FlxBitmapFont.fromAngelCode('assets/images/DigitalPup.png', 'assets/images/BMFont XML/DigitalPup.fnt');
var testtxtFont:FlxBitmapFont = FlxBitmapFont.fromAngelCode('assets/images/DigitalPup.png', 'assets/images/BMFont Text/DigitalPup.fnt');
var testBinaryFont:FlxBitmapFont = FlxBitmapFont.fromAngelCode('assets/images/DigitalPup.png', 'assets/images/BMFont Binary/DigitalPup.fnt');
tests = [
{
font: testXMLFont,
text: 'This font uses XML'
},
{
font: testtxtFont,
text: 'This font uses Text'
},
{
font: testBinaryFont,
text: 'This font uses Binary'
},
];
bmText = new FlxBitmapText(0, 0, tests[curIndex].text, tests[curIndex].font);
bmText.scale.scale(2.0);
bmText.screenCenter();
add(bmText);
}
function changeFontTo(index: Int)
{
bmText.text = tests[index].text;
bmText.font = tests[index].font;
}
override public function update(elapsed:Float)
{
super.update(elapsed);
if(FlxG.keys.justPressed.LEFT)
{
curIndex--;
if(curIndex < 0)
curIndex = 2;
changeFontTo(curIndex);
}
if(FlxG.keys.justPressed.RIGHT)
{
curIndex = (curIndex + 1) % 3;
changeFontTo(curIndex);
}
}
} |
Made some changes:
re - 1, 2, 3 and 4: What's left
|
I tested this on a few fonts I had and it seems to work (although I haven't tested with any fonts having kerning pairs yet).
Yeah I haven't seen any fonts without an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks like a great addition. I had a couple comments around cleanup and one potential bug.
This also looks like a good place for a couple unit tests to get some coverage of the code.
// var charCount = 0; | ||
// var kerningCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't appear to be part of the spec, but I've seen tools like Hiero put these lines in. Do you know where they come from / why they are here? Maybe just so human eyes can spot check the file for accuracy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know who Hiero is, but I assume the count is either to make sure you parsed correctly, or to aid in the parsing in some way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Mean to add link, but obviously didn't. Hiero is a libGDX font tool that I've used before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had generated a few fonts using BMFont and I saw these tags there. It doesn't seem to be part of the binary file spec but I did see them in the text and xml outputs
var xadvance:Int = 0; | ||
var page:Int = -1; | ||
var chnl:Int = -1; | ||
var letter:String = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a comment to call out that this isn't part of the spec and is here for debug purposes, if needed. (at least that's what I've gathered from this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't part of the spec
what does "this" refer to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.angelcode.com/products/bmfont/doc/file_format.html
Didn't realize this wasn't already in the PR description or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I was specifically calling out that letter
isn't in the spec, in case that's what you were asking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I found that the letter
field gets generated sometimes for the text/xml outputs (despite not being part of the spec) so I thought of adding it here just in case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why and when letter
appears in bmfont files, but it does, sometimes, so I figured it should be in the type as an optional field
@UncertainProd, I'm throwing together some unit tests for this that I'll put a PR against your branch hopefully later today along with a couple other changes related to my other comments. |
Thanks @UncertainProd and @MondayHopscotch ! |
FlxBitmapFont.fromAngelCode
used to work only with XML files generated by BMFont, but BMFont can also generate text or binary file descriptors. This pr should add support for all BMFont output format types. It also deprecatesFlxAngelCodeXmlAsset
which is now renamed toFlxAngelCodeAsset
since it can also support strings and bytes