Gange font color

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.
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Gange font color

Post by ishkabible »

how do you change font color, i can seem to figure this one out looking though the documentation. it always shows up white.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Gange font color

Post by nevon »

Code: Select all

function love.draw()
    love.graphics.setColor(255,0,0)
    love.graphics.print("Red text", x, y)
    love.graphics.setColor(0,0,0,127)
    love.graphics.print("Black text at 50% opacity", x, y)
end
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Gange font color

Post by ishkabible »

thanks, i had tired that before but nothing happened. i changed color mode this time to modulate before i called print then i changed it back to replace to achieve the effect i wanted
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Gange font color

Post by TechnoCat »

nevon wrote:

Code: Select all

function love.draw()
    love.graphics.setColor(255,0,0)
    love.graphics.print("Red text", x, y)
    love.graphics.setColor(0,0,0,127)
    love.graphics.print("Black text at 50% opacity", x, y)
end
I think it is worth noting that the color isn't cleared between callback calls.

Code: Select all

function love.draw()
    love.graphics.print("TEXT ONE", x, y)
    love.graphics.setColor(255,0,0)
    love.graphics.print("TEXT TWO", x, y)
    love.graphics.setColor(0,0,0,127)
    love.graphics.print("TEXT THREE", x, y)
end
Will print:

Code: Select all

(love.draw() call 1)
TEXT ONE (white opaque)
TEXT TWO (red opaque)
TEXT THREE (black half opaque)
(love.draw() call 2)
TEXT ONE (black half opaque)
TEXT TWO (red opaque)
TEXT THREE (black half opaque)
(love.draw() call 3)
TEXT ONE (black half opaque)
TEXT TWO (red opaque)
TEXT THREE (black half opaque)
...
Essentially making TEXT ONE and TEXT THREE the same color when it wraps around.

So some people might opt to put a love.setColor(255,255,255,255) at the beginning of love.draw()
Then:

Code: Select all

function love.draw()
    love.graphics.setColor(255,255,255,255)
    love.graphics.print("TEXT ONE", x, y)
    love.graphics.setColor(255,0,0)
    love.graphics.print("TEXT TWO", x, y)
    love.graphics.setColor(0,0,0,127)
    love.graphics.print("TEXT THREE", x, y)
end
Will print:

Code: Select all

(love.draw() call 1)
TEXT ONE (white opaque)
TEXT TWO (red opaque)
TEXT THREE (black half opaque)
(love.draw() call 2)
TEXT ONE (white opaque)
TEXT TWO (red opaque)
TEXT THREE (black half opaque)
...
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Gange font color

Post by ishkabible »

another thing i have not been able to find is how to change the alpha of an image when displayed without changing the color of the whole image aslo
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Gange font color

Post by TechnoCat »

ishkabible wrote:another thing i have not been able to find is how to change the alpha of an image when displayed without changing the color of the whole image aslo
if you keep the color as white, (255,255,255,alpha), and just change alpha, that should work to make images transparent.
I believe this is assuming your blending mode is default. Not too sure if changing the blending mode will change this.

Here is an example

Code: Select all

function love.load()
  image = love.graphics.newImage("girl.jpg")
  color = {}
  color.r = 255
  color.g = 255
  color.b = 255
  color.a = 255
end

function love.update(dt)
  color.a = color.a - dt*40
  if color.a < 0 then
    color.a = 255
  end
end

function love.draw()
  love.graphics.setColor(255,255,255,255)
  love.graphics.print("I am hidden text!", 0,0)
  love.graphics.setColor(color.r,color.g,color.b,color.a)
  love.graphics.draw(image, 0,0)
end
Attachments
imageAlpha.love
(167.46 KiB) Downloaded 59 times
Last edited by TechnoCat on Sun Oct 24, 2010 9:08 pm, edited 1 time in total.
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Gange font color

Post by ishkabible »

yep it worked, love is amazing, the productivity is astounding compared to what i have used in the past.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Gange font color

Post by Jasoco »

Does using SetColor and SetFont a lot slow down Löve at all? Or is there no impact at all on speed and no reason to optimize the code to reduce color/font calls?
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Gange font color

Post by thelinx »

Jasoco wrote:Does using SetColor and SetFont a lot slow down Löve at all? Or is there no impact at all on speed and no reason to optimize the code to reduce color/font calls?
Technically, it shouldn't.

The fonts are loaded into memory anyway and the colour is only used while drawing. The only overhead would probably be setting a C variable.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Gange font color

Post by Jasoco »

Good to know! Thanks. I was afraid calling them a lot would slow things down.
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests