How can I add fonts in different sizes?

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
InTheProcess
Prole
Posts: 11
Joined: Thu May 27, 2021 4:19 pm

How can I add fonts in different sizes?

Post by InTheProcess »

I passed in a table in the function and then throws an error; such as this "love.graphics.newFont(font[1],font[2])". How do I add a new font with a size parameter?
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: How can I add fonts in different sizes?

Post by GVovkiv »

InTheProcess wrote: Thu Jul 15, 2021 5:59 pm I passed in a table in the function and then throws an error; such as this "love.graphics.newFont(font[1],font[2])". How do I add a new font with a size parameter?
uh
maybe full source code?
applebappu
Prole
Posts: 37
Joined: Thu Jun 24, 2021 5:49 pm

Re: How can I add fonts in different sizes?

Post by applebappu »

Just keep it simple and use multiple lines, e.g.:

Code: Select all

font1 = love.graphics.newFont(courier.ttf, 10)
font2 = love.graphics.newFont(courier.ttf, 20)

love.graphics.setFont(font1)
...stuff that needs to be drawn in font1...

love.graphics.setFont(font2)
...stuff that needs to be drawn in font2...
Sure, you could compact it or whatever, but this makes it very clear what you're doing.

When you say "love.graphics.newFont(font[1],font[2])", you're trying to pass the thing in the second position of your font table as the argument to set the size of the first item in that table. Unless font = {font.ttf, integer} you're not going to get anything useful out of that. You should also assign the output of newFont somewhere, otherwise it's not going anywhere to be used.

documentation: https://love2d.org/wiki/love.graphics.newFont
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 12 guests