Page 1 of 1
Enlarge text?
Posted: Mon Sep 29, 2014 4:58 pm
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!
Re: Enlarge text?
Posted: Mon Sep 29, 2014 5:54 pm
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.
Re: Enlarge text?
Posted: Mon Sep 29, 2014 6:10 pm
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.
Re: Enlarge text?
Posted: Mon Sep 29, 2014 6:16 pm
by Chizbang
What am I best to use to shrink it down?
Re: Enlarge text?
Posted: Mon Sep 29, 2014 6:31 pm
by Robin
You could use [wiki]love.graphics.scale[/wiki].
Re: Enlarge text?
Posted: Tue Sep 30, 2014 12:56 am
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.
Re: Enlarge text?
Posted: Wed Oct 01, 2014 6:21 am
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.
Re: Enlarge text?
Posted: Wed Oct 01, 2014 7:30 pm
by Zilarrezko
Well now I seem like an idiot for putting that code in.
Re: Enlarge text?
Posted: Wed Oct 01, 2014 8:39 pm
by Jasoco
Don't. It's a common mistake that literally every newbie makes before they realize it.
Re: Enlarge text?
Posted: Wed Oct 01, 2014 9:28 pm
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