Color transparency
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Color transparency
I'm in the beginning stages of my game. I was wondering on how do I create something transparent in an image? Is there a specific color that makes LOVE ignore that color and make it transparent?
Re: Color transparency
No, LÖVE doesn't have any built-in support for that sort of thing. The easiest way is to make those pixels actually transparent in your images in the first place - use PNG, or some other file format that supports transparency.
Re: Color transparency
What color in a png format image would be transparent?
Re: Color transparency
A pixel with an alpha value of 0 is fully transparent. A format like PNG supports having pixels that are transparent, as opposed to a format like JPEG, which does not. Nearly all modern graphics editors support transparency (with the exception of, uh, Paint).
If you're having trouble getting an image to have transparent pixels in it, you can write some code that will do it for you. Let's say you've got a file called "hero.png" with a nice magenta color (RGB value: 255, 0, 255) as its background that you want to make transparent. First, you'd put this function somewhere in your code:
Then, when you want to load the image (in love.load, say), do this:
And you would then have an Image called "hero", with all the magenta parts of the image turned transparent.
However, I still recommend making the image itself transparent – that way, you don't have to use any of the code above, and can just create an Image from the file directly without worrying.
If you're having trouble getting an image to have transparent pixels in it, you can write some code that will do it for you. Let's say you've got a file called "hero.png" with a nice magenta color (RGB value: 255, 0, 255) as its background that you want to make transparent. First, you'd put this function somewhere in your code:
Code: Select all
function makeTransparent(x, y, r, g, b, a)
if r == 255 and g == 0 and b == 255 then
a = 0
end
return r,g,b,a
end
Code: Select all
local herodata = love.image.newImageData("hero.png")
herodata:mapPixel(makeTransparent)
hero = love.graphics.newImage(herodata)
However, I still recommend making the image itself transparent – that way, you don't have to use any of the code above, and can just create an Image from the file directly without worrying.
- zachwlewis
- Citizen
- Posts: 70
- Joined: Fri Mar 19, 2010 7:58 am
- Location: Huntsville, AL
- Contact:
Re: Color transparency
There is no one color that is transparent. In the image editor, you should be able to specify the transparency level of a color and paint with that.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Color transparency
Many graphics programs these days support alpha transparency and even layers so you should be fine with anything. I think newer versions of Paint? PhotoShop does and if you can't get PhotoShop, get Gimp. There are many others. Use Google.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], slime and 7 guests