Page 1 of 1

How to use imagefont?

Posted: Sat Feb 23, 2008 7:44 pm
by Green_Hell
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.

Re: How to use imagefont?

Posted: Sat Feb 23, 2008 8:05 pm
by Green_Hell
Ha! I get it. The problem was that I didn't have the specific separation color in the end of my imagefont picture. ;)

Re: How to use imagefont?

Posted: Sat Feb 23, 2008 10:08 pm
by Green_Hell
Another question. How shall I detect the width of my message created with imagefont?
Font:getWidth( line ) seems doesn't work :( .

Re: How to use imagefont?

Posted: Sat Feb 23, 2008 10:21 pm
by Green_Hell
Just as I thought. It works but after first draw. :roll:

Re: How to use imagefont?

Posted: Sun Feb 24, 2008 12:15 am
by rude
Whoa. So:
  • There's something fishy about font:getWidth(line) when using ImageFonts.
  • Need scaling of ImageFonts.
Shouldn't be a problem. ^^ (Mike?)

Re: How to use imagefont?

Posted: Sun Feb 24, 2008 12:42 pm
by mike
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.

Re: How to use imagefont?

Posted: Mon Feb 25, 2008 2:05 pm
by mike
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

Re: How to use imagefont?

Posted: Mon Feb 25, 2008 6:48 pm
by Green_Hell
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. :oops:
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.

Re: How to use imagefont?

Posted: Mon Feb 25, 2008 8:13 pm
by mike
Green_Hell wrote:If I was wrong, then sorry. :oops:
That's right. You're sorry! Hehe, don't worry about it. I wouldn't be surprised if it was a little buggy as I was "coding blind" when I made it, so this goes out to all followers: Any strange behavior (no matter how small) should be noted and reported. That is how we grow... 8-)