Do I need to set color to white before printf(coloredtext)?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Do I need to set color to white before printf(coloredtext)?

Post by randy0428 »

I have a program which is working as I want it to but I'm not sure why. I have the function below. (the entire project is also attached.) The "textoImprimido" variable in the printf line is defined in another function as "textoImprimido = {Cores.azulMaisEscuro, textoCombinado, Cores.amarelo, textoProximo}". The purpose of this is to print the "textoCombinado" variable as dark blue and the "textoProximo" variable in yellow.

The way the program is now, this works. But it only works properly if I set the color to white, "love.graphics.setColor(Cores.branco)", before the printf. If the color is not set to white, the second text variable is printed yellow as expected, but the first variable prints as black, not dark blue. Is it necessary to set the color to white before using a table as the text variable in a printf statement, or is there something else happening here?

Code: Select all

  imprimaTextoImprimido = function()
    love.graphics.setColor(Cores.branco)
    love.graphics.setFont(font24)
    love.graphics.printf(textoImprimido, 700, 155, 460, "left")   --imprime texto na caixaJogaTexto
    love.graphics.setColor(Cores.branco)
  end
Attachments
new_insects-2.zip
(1.66 MiB) Downloaded 77 times
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Do I need to set color to white before printf(coloredtext)?

Post by slime »

Yes, the color used in colored text and the global constant color are modulated (multiplied) together when drawing text.
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Resolved: Do I need to set color to white before printf(coloredtext)?

Post by randy0428 »

Thanks, slime.
I'd like to suggest a note be added to page https://love2d.org/wiki/love.graphics.printf explaining this. It could be something like I've shown below.
Thanks again.

Arguments
table coloredtext (Note: Set the color to 255, 255, 255 before using colored text in a variable because the color used in colored text and the global constant color are modulated (multiplied) together when drawing text.)
A table containing colors and strings to add to the object, in the form of {color1, string1, color2, string2, ...}.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Do I need to set color to white before printf(coloredtext)?

Post by raidho36 »

This is default for all drawing operations, and I think the module page makes that remark somewhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests