[SOLVED] Is there a way to get the string width and height?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Is there a way to get the string width and height?
Hey is there a way I can get the string width or height instead of font width and height only?
Last edited by YounYokel on Sat Oct 19, 2019 4:57 pm, edited 1 time in total.
- zorg
- Party member
- Posts: 3436
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Is there a way to get the string width and height?
Font:getWidth gets the width of a given text string in a specific font; Font:getHeight gives you the height of one line in that specific font. Not sure what else you might mean, unless you're asking for the number of characters (or codepoints) in a string, because that doesn't really have a width nor a height, those depend on the font used.
Me and my stuff True 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.
Re: Is there a way to get the string width and height?
Oh is that it? Is it important to create a new font before using this function (even if this font is default)? ~ cause normally I don't use any other fonts so I just don't change it.zorg wrote: ↑Sat Oct 19, 2019 1:02 pm Font:getWidth gets the width of a given text string in a specific font; Font:getHeight gives you the height of one line in that specific font. Not sure what else you might mean, unless you're asking for the number of characters (or codepoints) in a string, because that doesn't really have a width nor a height, those depend on the font used.
Code: Select all
font = love.graphics.newFont(14)
{
love.graphics.setFont(font)
local s="Hello, World!"
local sw,sh=font:getWidth(s),font:getHeight(s)
love.graphics.print(s.."\n"..tostring(sw).."\n"..tostring(sh))
}
Code: Select all
{
local s="Hello, World!"
local sw,sh=stringGetWidth(s), stringGetHeight(s)
love.graphics.print(s.."\n"..tostring(sw).."\n"..tostring(sh))
}
- zorg
- Party member
- Posts: 3436
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Is there a way to get the string width and height?
You don't need to create a new font, you can get the default font by just calling love.graphics.getFont.
My point was that that's still a font, because strings are abstract in the sense that without a font, they don't have width or height, just count (codepoint count if we're talking utf-8 or similar).
My point was that that's still a font, because strings are abstract in the sense that without a font, they don't have width or height, just count (codepoint count if we're talking utf-8 or similar).
Me and my stuff True 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.
Re: Is there a way to get the string width and height?
OK. Thanks for helping me!zorg wrote: ↑Sat Oct 19, 2019 2:06 pm You don't need to create a new font, you can get the default font by just calling love.graphics.getFont.
My point was that that's still a font, because strings are abstract in the sense that without a font, they don't have width or height, just count (codepoint count if we're talking utf-8 or similar).
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 48 guests