How to use imagefont?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

How to use imagefont?

Post 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.
>>I love LÖVE.<<
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

Re: How to use imagefont?

Post 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. ;)
>>I love LÖVE.<<
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

Re: How to use imagefont?

Post by Green_Hell »

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?

Post by Green_Hell »

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

Re: How to use imagefont?

Post 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?)
User avatar
mike
Administrator
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

Re: How to use imagefont?

Post 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.
Now posting IN STEREO (where available)
User avatar
mike
Administrator
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

Re: How to use imagefont?

Post 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
Now posting IN STEREO (where available)
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

Re: How to use imagefont?

Post 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.
>>I love LÖVE.<<
User avatar
mike
Administrator
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

Re: How to use imagefont?

Post 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-)
Now posting IN STEREO (where available)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 23 guests