Page 1 of 1
How to put two texts with two different sizes?
Posted: Wed Mar 01, 2017 4:44 pm
by Bernard51
Hi
How to put two texts with two different sizes?
If I put two fonts with 2 different sizes it does not work !
Code: Select all
local fontTitre1
local fontTitre2
fontTitre1 = love.graphics.newFont(100)
love.graphics.setFont(fontTitre1)
fontTitre2 = love.graphics.newFont(50)
love.graphics.setFont(fontTitre2)
[/code]
Thank you
Re: How to put two texts with two different sizes?
Posted: Wed Mar 01, 2017 4:49 pm
by bgordebak
You need to print them. Make variables in love.load() function, and set fonts before printing:
Code: Select all
function love.load()
font1 = love.graphics.newFont(50)
font2 = love.graphics.newFont(100)
end
function love.draw()
love.graphics.setFont(font1)
love.graphics.print("Some text with font1", 10, 10)
love.graphics.setFont(font2)
love.graphics.print("Some text with font2", 10, 100)
end
Alternatively, if the only thing you change is the size of the fonts, you can use setNewFont.
Code: Select all
funtion love.draw()
love.graphics.setNewFont(50)
love.graphics.print("Some text", 10, 10)
love.graphics.setNewFont(100)
love.graphics.print("Some other text", 10, 100)
end
Re: How to put two texts with two different sizes?
Posted: Wed Mar 01, 2017 4:58 pm
by Bernard51
thank you
Re: How to put two texts with two different sizes?
Posted: Wed Mar 01, 2017 6:11 pm
by Nixola
Do NOT use
love.graphics.setNewFont like that. It will quickly cause performance issues. Please read the wiki about that.
Re: How to put two texts with two different sizes?
Posted: Wed Mar 01, 2017 6:13 pm
by bgordebak
Sorry, yeah, that's right. I just wanted to show the alternate method, but I should've said that.
EDIT: It probably wouldn't matter if you don't have a lot of things going on in love.draw(), but when a game gets bigger, it can be a problem.
Re: How to put two texts with two different sizes?
Posted: Wed Mar 01, 2017 7:16 pm
by zorg
It's not only about processing speed, but the amount of garbage it creates in memory. Well, probably.
Re: How to put two texts with two different sizes?
Posted: Wed Mar 01, 2017 7:20 pm
by bgordebak
zorg wrote: ↑Wed Mar 01, 2017 7:16 pm
It's not only about processing speed, but the amount of garbage it creates in memory.
I didn't know that. Thanks!