Page 2 of 10
Re: I have a question.
Posted: Mon Oct 25, 2010 5:31 pm
by TechnoCat
com_1 wrote:LEN, MOD, SPLIT
Assuming this is asking for length, modulus, and string split, the answer is yes. This is because the entire
Lua language is at your disposal.
Length
http://www.lua.org/manual/5.1/manual.html#2.5.5
Modulus
http://www.lua.org/manual/5.1/manual.html#2.5.1
Split
http://lua-users.org/wiki/SplitJoin
Re: I have a question.
Posted: Mon Oct 25, 2010 5:50 pm
by Robin
com_1 wrote:LEN, MOD, SPLIT - is it possible on "Love2D" ?
If yes then how ?
LEN: if you mean the length of a string or table, #somestring or #sometable
MOD: if you mean the remainder of a division, a % b
SPLIT: if you mean splitting a string into substrings by means of delimiters, see
http://love2d.org/wiki/String_exploding
Re: I have a question.
Posted: Mon Oct 25, 2010 5:57 pm
by com_1
Thanks for your help.
It will take time, something to understand how it works.
I first saw(see) what LUA only a week ago. (thanks "Love2D")
Re: I have a question.
Posted: Tue Oct 26, 2010 10:23 pm
by com_1
font = love.graphics.setFont('courbi.ttf', 15);
// Not working ?
height = Font:getHeight(font)
width = Font:getWidth(font)
Where is the problem, please help.
Re: I have a question.
Posted: Tue Oct 26, 2010 10:35 pm
by TechnoCat
com_1 wrote:font = love.graphics.setFont('courbi.ttf', 15);
// Not working ?
height = Font:getHeight(font)
width = Font:getWidth(font)
Where is the problem, please help.
you probably wanted
Code: Select all
height = font:getHeight()
width = font:getWidth()
EDIT: DISREGARD THIS POST. IT IS WRONG.
Re: I have a question.
Posted: Tue Oct 26, 2010 10:58 pm
by com_1
font = love.graphics.setFont('courbi.ttf', 15)
height = Font:getHeight(font)
width = Font:getWidth(font)
Not working !!!
love.graphics.setFont('courbi.ttf', 15)
height = Font:getHeight()
width = Font:getWidth()
Not working !!!
Where is the PROBLEM, please ?
Re: I have a question.
Posted: Tue Oct 26, 2010 11:13 pm
by TechnoCat
com_1 wrote:font = love.graphics.setFont('courbi.ttf', 15)
height = Font:getHeight(font)
width = Font:getWidth(font)
Not working !!!
love.graphics.setFont('courbi.ttf', 15)
height = Font:getHeight()
width = Font:getWidth()
Not working !!!
Where is the PROBLEM, please ?
font = love.graphics.setFont('courbi.ttf', 15)
You are storing your font object in the variable 'font', notice the lowercase 'f'.
Then later you are trying to reference it with Font, with a capital 'F'.
I repeat:
Code: Select all
height = font:getHeight()
width = font:getWidth()
EDIT: DISREGARD THIS POST. IT IS WRONG.
Re: I have a question.
Posted: Wed Oct 27, 2010 5:47 am
by bartbes
Now wait a second... I don't think setFont returns a font object, does it? (It does not.)
Re: I have a question.
Posted: Wed Oct 27, 2010 9:22 am
by com_1
function love.load()
font = love.graphics.setFont("courbi.ttf", 15);
height = font:getHeight();
width = font:getWidth();
end
function love.draw()
love.graphics.print("my project",100,100,0,1,1);
end
Please, update this code.
Re: I have a question.
Posted: Wed Oct 27, 2010 9:47 am
by kikito
I think you need to use newFont first, and then use setFont - like this:
Code: Select all
function love.load()
font = love.graphics.newFont("courbi.ttf", 15); --changed 'setFont' to 'newFont'
height = font:getHeight();
end
function love.draw()
love.graphics.setFont(font); -- invoked setFont here
width = font:getWidth("my project"); -- moved getWidth here and added the string
love.graphics.print("my project",100,100,0,1,1);
end
Notice that you are not really using 'height' and 'width' at all; the program will work exactly the same if you do this:
Code: Select all
function love.load()
font = love.graphics.newFont("courbi.ttf", 15);
end
function love.draw()
love.graphics.setFont(font);
love.graphics.print("my project",100,100); -- the 0,1,1 parameters have default values, you don't need to add them
end
(btw guys, I still think that love.graphics.setFont(filename, size) and love.graphics.setFont(size) are a bad idea - they lead to confusion, as seen here. Separating font loading / creation from font setting is The Right Thing To Do)
EDIT: getWith needs the string