How to change the alpha/color of one string?
-
- Prole
- Posts: 5
- Joined: Fri Oct 03, 2014 9:07 pm
How to change the alpha/color of one string?
I'm trying to change the alpha of a string of text to get it to fade in. A while ago I had this working but since I've been revamping my code I can't seem to get the text to fade without having the background image fade as well. is there some vocabulary I might not know about, like stringvar:setColor(255) or something like that?
Re: How to change the alpha/color of one string?
You have to reset the color back to white after drawing the text:
Code: Select all
love.graphics.setColor(r,g,b) -- your text color
love.graphics.print('Hello World',100,100)
love.graphics.setColor(255,255,255) -- reset to white
Check out my blog on gamedev
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: How to change the alpha/color of one string?
Also you can use getColor to store the current color value in case you can't be certain of it before hand. So place it in a local and then reference it afterwards.
Code: Select all
love.graphics.setColor(0,0,255)
...
local oldColor = love.graphics.getColor()
love.graphics.setColor(255,0,0)
love.graphics.print("Some red text", 0, 0)
love.graphics.setColor(oldColor)
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: How to change the alpha/color of one string?
Both methods are right, but the guy wanted the alpha, which is the 4th argument.
Since it seems like you already set up the fade variable, all you need to do is this (based on what I think your code might look like):
Since it seems like you already set up the fade variable, all you need to do is this (based on what I think your code might look like):
Code: Select all
love.graphics.setBackgroundColor(red, green, blue, 255) --So your background doesn't fade. The "255" is required.
--It works with images or rectangles as well, just use love.graphics.setColor(red, green, blue, 255)
love.graphics.setColor(red, green, blue, alphaVariable) --Set this color for the string color that you want.
--Set the "alphaVariable" for the fading variable you already have.
--Draw the string here
love.graphics.setColor(red, green, blue, 255)
--Set this color for anything else you may have later, and draw them normally
Re: How to change the alpha/color of one string?
Jasoco, you need to store all components of the color. Your code only stores the red-value.
Code: Select all
local oldRed, oldGreen, oldBlue, oldAlpha = love.graphics.getColor()
love.graphics.setColor(255,0,0)
love.graphics.print("Some red text", 0, 0)
love.graphics.setColor(oldRed, oldGreen, oldBlue, oldAlpha)
Check out my blog on gamedev
Re: How to change the alpha/color of one string?
Or more simply
Code: Select all
local oldColor = { love.graphics.getColor() }
love.graphics.setColor(255,0,0,fadevalue)
love.graphics.print("Some red text", 0, 0)
love.graphics.setColor(oldColor)
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: How to change the alpha/color of one string?
It was an example. I wasn't showing off color. I was showing off renderTo(). The color is irrelevant. As is the text in my post.micha wrote:Jasoco, you need to store all components of the color. Your code only stores the red-value.
Code: Select all
local oldRed, oldGreen, oldBlue, oldAlpha = love.graphics.getColor() love.graphics.setColor(255,0,0) love.graphics.print("Some red text", 0, 0) love.graphics.setColor(oldRed, oldGreen, oldBlue, oldAlpha)
Who is online
Users browsing this forum: Semrush [Bot] and 3 guests