How to put two texts with two different sizes?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

How to put two texts with two different sizes?

Post 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
User avatar
bgordebak
Party member
Posts: 130
Joined: Thu Jul 10, 2014 2:04 am
Location: Ankara, Turkey

Re: How to put two texts with two different sizes?

Post 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
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

Re: How to put two texts with two different sizes?

Post by Bernard51 »

thank you
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: How to put two texts with two different sizes?

Post by Nixola »

Do NOT use love.graphics.setNewFont like that. It will quickly cause performance issues. Please read the wiki about that.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
bgordebak
Party member
Posts: 130
Joined: Thu Jul 10, 2014 2:04 am
Location: Ankara, Turkey

Re: How to put two texts with two different sizes?

Post 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.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to put two texts with two different sizes?

Post by zorg »

It's not only about processing speed, but the amount of garbage it creates in memory. Well, probably.
Last edited by zorg on Wed Mar 01, 2017 8:11 pm, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
bgordebak
Party member
Posts: 130
Joined: Thu Jul 10, 2014 2:04 am
Location: Ankara, Turkey

Re: How to put two texts with two different sizes?

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 256 guests