I have a question.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: I have a question.
Doesn't Font:getWidth() require a string as an argument?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: I have a question.
You are completely right - I've corrected my post.
When I write def I mean function.
Re: I have a question.
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
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: I have a question.
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().
Re: I have a question.
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)
Hello, I am not dead.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: I have a question.
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().
When I write def I mean function.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: I have a question.
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().
So to center text between x=100 and x=300, at y=400, do:
Code: Select all
love.graphics.printf("Our text", 100, 400, 200, "center")
Re: I have a question.
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
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: I have a question.
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
Help us help you: attach a .love.
Re: I have a question.
I don't understand why that wouldn't work.com_1 wrote:Code: Select all
love.graphics.printf("Thanks"..(" ")..("people"), 320, 240, 0, "center")
"Thanks" "people" of course wouldn't, unless you set the metatable of strings to automatically concatenate when __call is used.
Hello, I am not dead.
Who is online
Users browsing this forum: Bing [Bot] and 1 guest