Setting the colour of a Text object

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
benbaz4
Prole
Posts: 2
Joined: Tue Jan 10, 2017 8:53 pm

Setting the colour of a Text object

Post 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 !
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Setting the colour of a Text object

Post 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?
Me and my stuff :3True 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.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Setting the colour of a Text object

Post 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.
benbaz4
Prole
Posts: 2
Joined: Tue Jan 10, 2017 8:53 pm

Re: Setting the colour of a Text object

Post 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.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Setting the colour of a Text object

Post by zorg »

You can also do [wiki]Font:getWidth[/wiki](str) on a Font object though.
Me and my stuff :3True 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 188 guests