Page 1 of 1

Setting the colour of a Text object

Posted: Tue Jan 10, 2017 9:07 pm
by benbaz4
Hi there,
I'm a super newbie and this question might sound silly but I can't find how to set the colour of a Text object. I mean, by default, if you draw a Text object, it displays white text, and I didn't find what property I should change to display black text, by exemple.
Sorry if this is obvious, and thank you for your help !

Re: Setting the colour of a Text object

Posted: Tue Jan 10, 2017 9:48 pm
by zorg
Hi and welcome to the forums.

First question, do you really want to use a Text object? Or would you be fine with just printing stuff to the window?

Re: Setting the colour of a Text object

Posted: Tue Jan 10, 2017 10:48 pm
by slime
Either way, you can set the color of the entire text with [wiki]love.graphics.setColor[/wiki] before you draw it. Alternatively, love.graphics.print/printf and Text:set/add/etc. all optionally accept a table in the form of {{r, g, b}, "text", {r, g, b}, "more text", ...} which allows different parts of the same text to have different colors.

Re: Setting the colour of a Text object

Posted: Wed Jan 11, 2017 11:41 am
by benbaz4
Thanks for both answers.

@zorg : I use a Text object because I also use the Text:getWidth method.

@slime : I've tried your solution and it worked perfectly. Thanks a lot.

Re: Setting the colour of a Text object

Posted: Wed Jan 11, 2017 12:13 pm
by zorg
You can also do [wiki]Font:getWidth[/wiki](str) on a Font object though.