Gange font color
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Gange font color
how do you change font color, i can seem to figure this one out looking though the documentation. it always shows up white.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Gange font color
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
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Re: Gange font color
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
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Gange font color
I think it is worth noting that the color isn't cleared between callback calls.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
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
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)
...
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
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)
...
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Re: Gange font color
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
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Gange font color
if you keep the color as white, (255,255,255,alpha), and just change alpha, that should work to make images transparent.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
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.
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Re: Gange font color
yep it worked, love is amazing, the productivity is astounding compared to what i have used in the past.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Gange font color
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?
Re: Gange font color
Technically, it shouldn't.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?
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.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Gange font color
Good to know! Thanks. I was afraid calling them a lot would slow things down.
Who is online
Users browsing this forum: No registered users and 57 guests