Re: I have a question.
Posted: Wed Oct 27, 2010 9:52 am
Doesn't Font:getWidth() require a string as an argument?
Code: Select all
function love.load()
scrx = 640; scry = 480; zx = (scrx/2); zy = (scry/2); zi=200;
love.graphics.setMode(scrx, scry, false, true, 0);
font = love.graphics.newFont("courbi.ttf", 15); --changed 'setFont' to 'newFont'
height = font:getHeight();
end
function love.draw()
love.graphics.line(zx - zi, zy, zx + zi, zy); love.graphics.line(zx, zy - zi, zx, zy + zi);
love.graphics.setFont(font); -- invoked setFont here
i = "Thanks people";
width = font:getWidth(i); -- moved getWidth here and added the string
love.graphics.print(i, zx - (width/2), zy + (height/5));
end
nevon wrote:com_1, do take a look at love.graphics.printf(). It's very handy when you're just trying to center text. Saves you the trouble of having to do a bunch of getWidth()/getHeight().
Code: Select all
local myStr="Hi there"
love.graphics.print(myStr,myX-myFont:getWidth(myStr)/2,myY)
I'm afraid that love.graphics.draw (for images) has the 'cx,cy' params, but print/printf don't - unless the wiki is incomplete.nevon wrote:com_1, do take a look at love.graphics.printf(). It's very handy when you're just trying to center text. Saves you the trouble of having to do a bunch of getWidth()/getHeight().
You don't need them. love.graphics.printf( text, x, y, limit, align )kikito wrote:I'm afraid that love.graphics.draw (for images) has the 'cx,cy' params, but print/printf don't - unless the wiki is incomplete.nevon wrote:com_1, do take a look at love.graphics.printf(). It's very handy when you're just trying to center text. Saves you the trouble of having to do a bunch of getWidth()/getHeight().
Code: Select all
love.graphics.printf("Our text", 100, 400, 200, "center")
Code: Select all
//With
love.graphics.printf("Thanks people", 320, 240, 0, "center")
//or
love.graphics.printf("Thanks"..(" ")..("people"), 320, 240, 0, "center")
//Not possible
Why the second one, may I ask?com_1 wrote:Code: Select all
//With love.graphics.printf("Thanks people", 320, 240, 0, "center") //or love.graphics.printf("Thanks"..(" ")..("people"), 320, 240, 0, "center") //Not possible
I don't understand why that wouldn't work.com_1 wrote:Code: Select all
love.graphics.printf("Thanks"..(" ")..("people"), 320, 240, 0, "center")