I want 2 texts with the same font but with 2 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.
Bernard51
Prole
Posts: 36
Joined: Fri Jan 20, 2017 5:51 pm

I want 2 texts with the same font but with 2 different sizes??

Post by Bernard51 » Fri Aug 10, 2018 5:23 am

Hello

I'm loading a .tff file and using a size of 120, How to put a second text with the same font but with a size of 50, basically I want 2 texts with the same font but with 2 different sizes ??
https://www.dropbox.com/s/nwkjaetppb99b ... 1.zip?dl=0
Thank you Bernard

User avatar
zorg
Party member
Posts: 2325
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I want 2 texts with the same font but with 2 different sizes??

Post by zorg » Fri Aug 10, 2018 6:58 am

create another font with the same ttf file, but with a size of 50; assuming you assigned both of them to separate variables, you can setFont them whenever you want to switch fonts.
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.

Bernard51
Prole
Posts: 36
Joined: Fri Jan 20, 2017 5:51 pm

Re: I want 2 texts with the same font but with 2 different sizes??

Post by Bernard51 » Fri Aug 10, 2018 7:53 am

thank you

I have to reload the same file twice with a different size?

User avatar
zorg
Party member
Posts: 2325
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I want 2 texts with the same font but with 2 different sizes??

Post by zorg » Fri Aug 10, 2018 9:51 am

It seems to be that way, though i'm not sure whether there are any optimizations under the hood or not;

I wanted to say that you could cheat a bit by creating a Rasterizer instead, and then creating two differently sized fonts using that instead of the font file, but apparently the rasterizers themselves require the font size to be defined, so even if love.graphics.newFont coult take a Rasterizer object, we would not have moved forward too much.

Then again, love.graphics.newFont might accept a FileData object, so you could load the file itself into RAM only once, and use that to create two fonts with different sizes; that may be a viable solution...
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.

Bernard51
Prole
Posts: 36
Joined: Fri Jan 20, 2017 5:51 pm

Re: I want 2 texts with the same font but with 2 different sizes??

Post by Bernard51 » Fri Aug 10, 2018 12:55 pm

thank you

do you have a tutorial on fileData?

User avatar
zorg
Party member
Posts: 2325
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I want 2 texts with the same font but with 2 different sizes??

Post by zorg » Fri Aug 10, 2018 1:47 pm

Apart from clicking the link in my previous post that takes you to its wiki article, here's a quick code you can look at:

Code: Select all

myFontFileData = love.filesystem.newFileData('relative.path.to.your.font.ttf')
myFont120pt = love.graphics.newFont(myFontFileData, 120)
myFont50pt = love.graphics.newFont(myFontFileData, 50)
-- of course, you could also have just one table called myFont, and have the 50th and 120th index be the Font objects you create; it's a matter of preference only, though.
Then again, i'm making an assumption here that love.graphics.newFont being able to take a FileData as its parameter, since a lot of functions can that aren't necessarily notated on the wiki as such. If it doesn't support it, then we're back to the original solution, creating the two sizes of the same font twice from disk.
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.

Bernard51
Prole
Posts: 36
Joined: Fri Jan 20, 2017 5:51 pm

Re: I want 2 texts with the same font but with 2 different sizes??

Post by Bernard51 » Fri Aug 10, 2018 1:58 pm

Thank you very much

Nelvin
Prole
Posts: 36
Joined: Mon Sep 12, 2016 7:52 am

Re: I want 2 texts with the same font but with 2 different sizes??

Post by Nelvin » Fri Aug 10, 2018 3:15 pm

Just some additional info ... if you use lots of different characters in a pretty big size your area of interest might be the required resources for the cached bitmaps/textures of the font instead of the loaded ttf-file. The bitmaps for the characters will be created and cached by love automatically (only those you actually used, so it highly depends on what you print and how many different fonts and sizes you use).

Bernard51
Prole
Posts: 36
Joined: Fri Jan 20, 2017 5:51 pm

Re: I want 2 texts with the same font but with 2 different sizes??

Post by Bernard51 » Fri Aug 10, 2018 3:55 pm

Thank you very much

User avatar
pgimeno
Party member
Posts: 1177
Joined: Sun Oct 18, 2015 2:58 pm

Re: I want 2 texts with the same font but with 2 different sizes??

Post by pgimeno » Fri Aug 10, 2018 6:21 pm

"All variants which accept a filename can also accept a Data object instead." - love.graphics.newFont

A FileData object is a Data object. It's documented to work.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories
The Microsoft Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests