Transparency

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Iskai
Prole
Posts: 4
Joined: Mon Apr 04, 2011 9:18 pm

Transparency

Post by Iskai »

Hi there. What's the recommended way of handling transparency with LOVE? I have a spritesheet in which my sprites are drawn on a magenta background (I previously used this with an SDL version of the same app) but I can't seem to figure out how to draw them without the magenta background.

Using setColor and setBackgroundColor just stops everything from being displayed - most frustrating.

It's my first time with LOVE and i'm....um... loving it.
Attachments
ponggame.love
(2.06 KiB) Downloaded 238 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Transparency

Post by Robin »

You can use transparency in a decent image editor, LÖVE will use that. Use the eraser, or the color-to-alpha function like the gimp has.
Help us help you: attach a .love.
Iskai
Prole
Posts: 4
Joined: Mon Apr 04, 2011 9:18 pm

Re: Transparency

Post by Iskai »

I was kind of thinking that yes, perhaps I could use a file format that supports transparency. I was more wondering if using existing assets (such as my spritesheet) was possible or must I modify it specially to work with LOVE?
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Transparency

Post by Taehl »

Using alpha channels isn't a Love-specific thing, it's standard for EVERYTHING. The only reason that "magic magenta"/"garish green" thing ever caught on was due to .gif being popular before .png came around and did everything better.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Transparency

Post by Jasoco »

I remember my DOOM hacking days. So much magenta. Soooo much magentaaaaa...

Use PNG. Or GIF. And don't use Paint.exe. Use Gimp or Photoshop or one of the hundreds of better free and paid image editors out there fore Windows, Linux or Mac.
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: Transparency

Post by Ensayia »

It sort of amazes me that the paint program provided with the most recent Windows doesn't support layers or any sort of transparency whatsoever. Microsoft even upgraded the calculator! Poor paint gets forgotten...
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Transparency

Post by Jasoco »

But it has the Ribbon! Also known as the dividing line between two groups of people in an argument over whether the ribbon is awesome or the ribbon sucks. I'm in the "The ribbon is confusing as hell and they should just stick with menus and toolbars" camp actually.

Paint has everything BUT layers now. While IE9 is going the simplistic route, the rest of Windows is going the "complicate the interface to the point of confusion" route.
NBoF5.png
NBoF5.png (427.91 KiB) Viewed 638 times
Windows doesn't even have a native PDF support that OS X has had since 2000.
User avatar
sharpobject
Prole
Posts: 44
Joined: Fri Mar 18, 2011 2:32 pm
Location: California

Re: Transparency

Post by sharpobject »

Code: Select all

#!/usr/bin/python
from PIL import Image
import _imaging
import sys
for arg in sys.argv:
    img = None
    try:
        img = Image.open(arg)
    except:
        continue
    img = img.convert("RGBA")
    datas = img.getdata()
    newData = []
    for r,g,b,a in datas:
        if r == 255 and g == 0 and b == 255:
            newData.append((255, 255, 255, 0))
        else:
            newData.append((r,g,b,a))
    img.putdata(newData)
    img.save(arg+".png")

Code: Select all

dripping:demo robert$ ls
image_0.bmp		image_1.bmp		maketransparent.py
dripping:demo robert$ ./maketransparent.py *
dripping:demo robert$ ls
image_0.bmp		image_1.bmp		maketransparent.py
image_0.bmp.png		image_1.bmp.png
Iskai
Prole
Posts: 4
Joined: Mon Apr 04, 2011 9:18 pm

Re: Transparency

Post by Iskai »

I'm not saying that the whole magenta transparency thing is better or anything - I was just wondering if I'd missed something as there didn't seem to be an obvious way to define that colour as transparency. Based on your replies though, I'll simply use a PNG with transparency.
Jasoco wrote: And don't use Paint.exe. Use Gimp or Photoshop or one of the hundreds of better free and paid image editors out there fore Windows, Linux or Mac.
I actually made my images with http://www.aseprite.org/ - thankfully it supports those image formats as well. I wouldn't use MSPaint when there are much better, free alternatives available.

Thanks for the help!
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Transparency

Post by TechnoCat »

Iskai wrote:I'm not saying that the whole magenta transparency thing is better or anything - I was just wondering if I'd missed something as there didn't seem to be an obvious way to define that colour as transparency.
Thanks for the help!
there is an obvious way to do it. I'm not sure why everyone else is sidetracking the question. However, the HUGE disadvantage to using magenta is the lack of alphas between 0 and 255.

imageFile -> ImageData
ImageData->mapPixel()
return a=0 if magenta
imageData -> image
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests