## How to use imagefont?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

### How to use imagefont?

I'm able to make and draw imagefont but I'm not able to draw quotation mark. I mean >> " <<.
In Tutorial 3: Fonts and Text is this small example

Code: Select all

font = love.objects:newImageFont("imagefont.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&'*#=[]\"")
and before " is escape character \. I did it but love didn't draw it. Even if i use ' instead of " to mark string in draw method.

And I have one more question or maybe idea. Is it possible to use smaller source font and resize it inside the game? If i want pixel font i have to resize it to see large pixels and it also means two-times bigger source image.
>>I love LÖVE.<<
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

### Re: How to use imagefont?

Ha! I get it. The problem was that I didn't have the specific separation color in the end of my imagefont picture.
>>I love LÖVE.<<
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

### Re: How to use imagefont?

Another question. How shall I detect the width of my message created with imagefont?
Font:getWidth( line ) seems doesn't work .
>>I love LÖVE.<<
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

### Re: How to use imagefont?

Just as I thought. It works but after first draw.
>>I love LÖVE.<<
rude
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

### Re: How to use imagefont?

Whoa. So:
• There's something fishy about font:getWidth(line) when using ImageFonts.
• Need scaling of ImageFonts.
Shouldn't be a problem. (Mike?)
mike
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

### Re: How to use imagefont?

ImageFont is generally confusing and gay (not really gay, but still I didn't test it thoroughly before releasing). Working on a bunch of fixes for the next version and this is all VERY helpful.

edit: Fixed the tutorial to mention the fact that the separation color needs to be at the end of the image as well (the image scanning algorithm will change to something more logical soon, but it will still be important) and I actually got something wrong: you do not need to set color mode to love.color_modulate for the current color to affect imagefonts. That is a mistake. And a lie.
Now posting IN STEREO (where available)
mike
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

### Re: How to use imagefont?

I am not sure what is going wrong with getWidth() as this code (which calls getWidth() before the first draw()) works... could you post an erroneous example?

Code: Select all

function load()

local font = love.objects:newImageFont("imagefont.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&'*#=[]\"")
love.graphics:setFont(font)
num = font:getWidth("BUTT")

end

function draw()

love.graphics:draw("BUTT:" .. num, 100, 100)

end

Now posting IN STEREO (where available)
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

### Re: How to use imagefont?

It was in early startfield demo code. And I've just put it in load() and it works. It's possible that it was just a mistake in my code. I've also change the image font many times. But I remember that it didn't work and when I drew it it worked. If I was wrong, then sorry.
Unfortunately I don't have the old version . I think the problem was that I didn't draw it at all but I also tried it and it worked fine.
>>I love LÖVE.<<
mike