Hi all,
There was some discussion about bitmap fonts with MPF on another platform, and I wanted to share a working example for those that are figuring it out.
This biggest "gotcha" I found was that there's a specific file structure and location that has to be used or it doesn't work (or at least didn't for me):
...so, a folder called "bitmap_fonts" has to be at the top level of your game, and inside that are the font definitions and the images used. I've got six fonts in this example, basically different sizes and colors of the same font.
The font definition file (very stripped down) looks like this:
info face=font size= bold= italic= charset= unicode= stretchH= smooth= aa= padding=0,0,0,0 spacing=0,0 outline=0
common lineHeight=55 base=55 scaleW=40 scaleH=55 pages=1 packed=0
page id=0 file="bitmapFontBallySevenSegment4.png"
chars count=11
char id=48 x=0 y=0 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=49 x=0 y=55 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=50 x=0 y=110 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=51 x=0 y=165 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=52 x=0 y=220 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=53 x=0 y=275 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=54 x=0 y=330 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=55 x=0 y=385 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=56 x=0 y=440 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=57 x=0 y=495 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
char id=32 x=0 y=550 width=40 height=55 xoffset=0 yoffset=0 xadvance=40 page=0 chnl=15
...and a typical corresponding image file is this:
Some things to note:
- The file name of the image is defined in the .FNT file
- The ASCII code for each character is defined by a starting position (x, y for the upper left corner)
- ...and a width and height value.
At this point I'm able to use it in a config directly like so:
slides:
slideBaseBackglass:
widgets:
- type: image
image: imagebackglass
z: 40
# --------------------
# BITMAP FONT TEST
# --------------------
- type: text
text: (player1|score)
z: 30
x: left + 730
y: bottom + 787
anchor_x: right
anchor_y: middle
font_name: bitmapFontBallySevenSegment4
bitmap_font: true
Hope this helps,
Brian Cox