Enlarge text?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Enlarge text?
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!
- Zilarrezko
- Party member
- Posts: 345
- Joined: Mon Dec 10, 2012 5:50 am
- Location: Oregon
Re: Enlarge text?
I do not by anymeans can think of an effecient way to do this right now. But here it goes...
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.
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
This may be the simplest way. But Someone might come along and give a more efficient way.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Enlarge text?
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.
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?
What am I best to use to shrink it down?
Re: Enlarge text?
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
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Enlarge text?
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.
- Zilarrezko
- Party member
- Posts: 345
- Joined: Mon Dec 10, 2012 5:50 am
- Location: Oregon
Re: Enlarge text?
Well now I seem like an idiot for putting that code in.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Enlarge text?
Don't. It's a common mistake that literally every newbie makes before they realize it.
- Zilarrezko
- Party member
- Posts: 345
- Joined: Mon Dec 10, 2012 5:50 am
- Location: Oregon
Re: Enlarge text?
I thought of myself as an intermediataryJasoco wrote:Don't. It's a common mistake that literally every newbie makes before they realize it.
Who is online
Users browsing this forum: Google [Bot] and 1 guest