[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Introductions and question about transparency




Hello again!

A note first: the URL I gave earlier for the images is down for the moment. 
My brother seems to have decided that today is a good day to move the server. 
:-) Will be up again later tonight if we are lucky.

Pete Shinners -- Lundi 21 Mai 2001 17:27:
> hello jerome, welcome to the list. wow, it looks like you are off
> to a great start. the type of transparancy you are looking for is
> named "colorkey transparancy". this means that a given color of the
> image is drawn transparantly when blitting.
>
> you say you are loading from XPM images. i'm not sure if XPM images
> can store a colorkey value like GIF and PNG can. i'm guessing it does
> not, since the image loaders in SDL_image will usually preserve any
> transparancy/colorkey values in the image.

I thought the same thing at first, so I decided to investigate. The Gimp 
seems to believe the background is transparent (checkered pattern) and 
displays some truly-white pixels in some tiles (ie arctic).

Exporting the image to gif and png gives me transparent gif and png images. I 
tested this by making a webpage with a grey background containg <IMG> tags to 
all images and loading it in Konqueror. The images are transparent.

I surmised maybe SDL_Image does not support XPM transparency. So I tried 
loading my bigtile from the converted GIF and PNG images. That did not work 
either. I am a bit puzzled.

>
> what you will want to do is set the colorkey for the "big tile map"
> image after it is loaded...
>
>     bigtile_surface = pygame.image.load(tile_filename).convert()
>     colorkey = 255, 255, 255
>     bigtile_surface.set_colorkey(colorkey)

I would really like the image's transparency to work normally, but I did try 
your advice. I learned a bit doing it too. :-) It did not work immediately, 
but I remembered your docs and called set_colorkey on the subsurfaces 
instead. That worked.

However, it did not work with the original trident tiles. The transparency 
did not trigger the colorkey, even though it appears as white once blitted. I 
had to add a white background layer with the Gimp (destroying the existing 
transparency) before it would work.

Any more clues? I can put up a tarball of the code somewhere if you want a 
look. (Though I would have preferred to not show it right away.)

This means as a side-effect that some tiles which are supposed to be an 
opaque white will not survive the process. Some tiles have both transparency 
and white pixels (ie jewels and gold resource tiles)... Problematic.


>
> this should do the job for you. it will make the "white" pixels
> transparent when blitting.
>
>
>
> your code looks very well put together so far. i look forward to
> seeing something playable :]

So do I. :-)

Thanks very much for your time. I hope you think of something else.

PS: Great work on SolarWolf, by the way. One of the most all-around polished 
free games available for Linux, in my humble opinion. You should do a binary 
distribution with 'freeze', though. That is possible with pygame, isn't it?


-- 
Jérôme Loisel, étudiant et webmestre
Lévinux: GNU/Linux pour la communauté
http://www.levinux.org/
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org