Transparency issues

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.
Post Reply
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Transparency issues

Post by Lord Tim »

Hello, all.

I've been working on my latest game in none other than the wonderous Löve, and I've come across a strange glitch. Some of my sprites have thin magenta borders around them, while other do not. I am using magenta as the transparency color, but the other parts that are magenta are transparent as they should be. I am using mtPaint to create my images (.png).

Here's an example:
(The guy on the top's x/y/a is connected to a physics object, the bottom is a static sprite, both are drawn from love.graphics.draw(sprite,x,y,a) with the same Image object)
Image

Is this because of the way I'm making the actual image? Or is it a Löve/Lua/OpenGL issue? Any way to fix it?
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Transparency issues

Post by qubodup »

Anti-aliasing?

Are the bordered images JPG? (Well, if you say PNG, apparently not)

Please upload a working and a not-working image.

Curiosity: Why do you use a color instead of real transparency?

PS: Perhaps it has to do with 'indexed' status of the images.

PPS: Maybe uploading the code would help too.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Transparency issues

Post by rude »

This is probably due to how PNG handles transparent textures when scaled/rotated/translated. I added a feature a while back (which noone cared about at the time) which took care of this problem. I tested it a while ago, and it seems to be broken in 0.5.0. :D Typical.

You can try it if you want, maybe I'm mistaken. Load the image like this:

Code: Select all

image = love.graphics.newImage("fist.png", love.image_optimize)
If you math.floor the x,y-position before drawing the sprite, the problem will go away, though. (Unless you scale/rotate it). Of course, that will also lead to non-smooth movement.
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Re: Transparency issues

Post by Lord Tim »

Cool, thanks for that.

I had already tried out the optimize setting before, but yeah, doesn't fix the problem.

Is there a better way to add the transparency to images? I'm a bit new at that, and the index option seemed the easiest.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Transparency issues

Post by bartbes »

Gimp has an option to convert a color to alpha, don't know exactly if it works as you need it to, it is located under color (and is called color to alpha, or something similar).
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Re: Transparency issues

Post by Lord Tim »

Would a different image format not have this problem? Like if I used .gif instead?
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Transparency issues

Post by qubodup »

bartbes wrote:Gimp has an option to convert a color to alpha, don't know exactly if it works as you need it to, it is located under color (and is called color to alpha, or something similar).
I do it by right-clicking the layer (in the layer dialog) and clicking "add alpha to layer" then, when you erase or delete (DEL) pixels, they are transparent.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Transparency issues

Post by rude »

If you fill the magenta areas with black and use a TGA transparency mask for the transparent areas it will probably solve your problem.
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Re: Transparency issues

Post by Lord Tim »

Ah. Thanks. Using .tga fixes this.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest