Enlarge text?

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
Chizbang
Prole
Posts: 2
Joined: Mon Sep 29, 2014 4:56 pm

Enlarge text?

Post by Chizbang »

How would I go about enlarging text by dt? I want to have a bit of text in the center of the screen that starts out small and over a few ms, gets larger. Any ideas? Thanks! :)
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

Re: Enlarge text?

Post by Zilarrezko »

I do not by anymeans can think of an effecient way to do this right now. But here it goes...

Code: Select all

function love.load()
     textsize = 12
     coefficent = 1 -- This is in case you want the text to get bigger faster or slower
end

function love.update(dt)
      textsize = textsize + dt * coefficent
     love.graphics.setFont(love.graphics.newFont(textsize))
end

function love.draw()
     love.graphics.print(textsize, 10, 10)
end
Not sure what this will do with performance later on in the game. But I don't have time to research how fonts are loaded and de allocated from memory right now (college starts tomorrow). But I think it's fine, just because I think the returned love.graphics.newFont isn't being saved into memory somewhere, just passed into love.graphics.setFont.

This may be the simplest way. But Someone might come along and give a more efficient way.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Enlarge text?

Post by Jasoco »

Do not call newFont in update or draw.

To solve the OP, just create a font at the largest size and shrink it down to the size you want. Will make a lot more sense than creating a font size for every size you need.
Chizbang
Prole
Posts: 2
Joined: Mon Sep 29, 2014 4:56 pm

Re: Enlarge text?

Post by Chizbang »

What am I best to use to shrink it down?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Enlarge text?

Post by Robin »

You could use [wiki]love.graphics.scale[/wiki].
Help us help you: attach a .love.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Enlarge text?

Post by davisdude »

Robin's approach is the best. If you are worried about scaling other objects, just make the text a canvas and scale that.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Enlarge text?

Post by Jasoco »

As long as you push before scaling before drawing then pop immediately after, you won't have to worry about accidentally scaling other things. You can even use multiple manipulations in the same set. Like if you want to be able to have something scale from the center, you first translate to its X and Y center location, call scale at the current scale value, then translate at negative half the width and height of what you're drawing, then draw it. It'll scale from its center. If the first X and Y values are half the width and height of the screen then it'll be centered. You can also then use rotate to rotate it around its center. All without having to use Canvas.
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

Re: Enlarge text?

Post by Zilarrezko »

Well now I seem like an idiot for putting that code in.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Enlarge text?

Post by Jasoco »

Don't. It's a common mistake that literally every newbie makes before they realize it.
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

Re: Enlarge text?

Post by Zilarrezko »

Jasoco wrote:Don't. It's a common mistake that literally every newbie makes before they realize it.
I thought of myself as an intermediatary :cry:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests