Font doesn't seem to be using the .fnt file

I’m using: Roobert-24-Medium-table-36-36.png Roobert-24-Medium.fnt files from the Resources/Fonts folder of the SDK but no matter how I change the .fnt file it doesn’t seem to affect the font on screen. Do I also need to load the .fnt file somehow (as well as the .png)?

I was trying to adjust the spacing of “11” like it shows in the docs but it doesn’t seem to be working.

Thanks

Take a look through the Examples folder. A bunch of those use font loading.

Also from the docs:

Font instance functions

playdate.graphics.font:drawText(text, x, y)

Draws a string at the specified x, y coordinate using this particular font instance. (Compare to playdate.graphics.drawText(text, x, y), which draws the string with whatever the “current font”, as defined by playdate.graphics.setFont(font)).

So you should be doing something like:

myRoobertFontInstance = playdate.graphics.font.new("Roobert-24-Medium")
myRoobertFontInstance:drawText(text, x, y)

or

myRoobertFontInstance = playdate.graphics.font.new("Roobert-24-Medium")
playdate.graphics.setFont(myRoobertFontInstance)
playdate.graphics.drawText(text, x, y)

I’m doing exactly what you’re showing above, and my font shows up just like it should, it just doesn’t seem to take the .fnt file into account. I wanted to have more space between the one’s in the number eleven just like they show in the docs (Inside Playdate - under text) but no matter what number I put in there to add more space it doesn’t work.

I have tried extreme numbers and nothing happens, even the first two listings in the .fnt file don’t seem to be taken into account (tracking and space) it just seems like the SDK on compiling is not using it, and I even checked the naming of the 2 files (the .png vs the .fnt) seems like a bug.

1 Like

OK, I even went and tweeked the spacing in the .fnt file in the 2020 game example and it didn’t change anything, hmm :thinking:

I’m not sure exactly what you’re changing?

In code use setFontTracking(). This increases spacing between all characters.

In the .fnt file (loaded automatically along with the PNG as you don’t specify a file extension) you can specify

  • default tracking, or
  • per character spacing, or
  • kerning pair spacing (between a specific pair of characters)

I’ve just done the credits roll for my game and I have wider/longer tracking, using setFontTracking(), so it does work.

Finally try deleting the .pdx and doing a fresh run/install. You could check the contents of the .pdx too.

I’ve used that too, works fine.

look in the resource/fonts folder - notice that each font consists of a .png and a matching .fnt file, if you look at the .fnt file with a text editor you will see two columns - the first entry or two start with space and sometimes also tracking then the rest of the file is the character on the left and a number for the width of that character, then farther down the list is special info for custom spacing, etc.

search the Inside Playdate.html for this [Sample .fnt file excerp] to see what I’m talking about, the third example down shows what I’m talking about, it’s being ignored. you should be able to put some custom spacing in there on a character by character basis. Unless I’m reading that wrong.

1 Like

I see what you mean. In the docs it’s showing two lower case Ls. So, ll 3 put three extra pixels between two lower case Ls. Would be visible in the word wall for example.

The font editor shows this visually which I appreciate you’re not able to use.

Now you got it, doesn’t seem to be working

See if you can tweak some numbers in one of the fonts to see if it has any affect

I do it all the time, all three methods I listed above work for me.

I think there’s a compiler bug there–if you make a change to the fnt file and recompile the compiler doesn’t realize it needs to update the compiled font because its timestamp is newer than the png file. If you delete the pdx and rebuild from scratch I believe you’ll see the kerning and spacing changes.

1 Like

Thanks Dave, I’ll try that and let you know if it works.

That did it, thanks :blush:

2 Likes

it is old thread, but I am doing exactly this and I am not able to load the Roobert-24-Medium.

the error I get is: main.lua:17: attempt to index a nil value (global 'myRoobertFontInstance')

that implies a scope issue.

check local/global of your font instance/variable.

I don't understand, apologize! Here is the code, and yet I am not able to change the font!

import "CoreLibs/graphics"
local gfx <const> = playdate.graphics
myRoobertFontInstance = gfx.font.new("Roobert-24-Medium")
gfx.setFont(myRoobertFontInstance)

function playdate.update()
gfx.drawText("test", 10, 10)
end

Thank you.

make sure your font file "Roobert-24-Medium" is in the expected location.

the below code will stop if the file is not loaded correctly.

myRoobertFontInstance = gfx.font.new("Roobert-24-Medium")
assert(myRoobertFontInstance)
gfx.setFont(myRoobertFontInstance)

Thank you, Matt! It works. The font it was in the wrong category!

2 Likes