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

Re: [pygame] Image alpha control?



Richard Jones wrote:

> I'm trying to do some alpha-based image manipulations. The initial image is a 
> font.render()'ed text surface, and it's easy to deal with, because I just use 
> set_alpha(255) on it and I can blit it to my window surface and the black 
> doesn't blot out existing imagery.


first thing to make clear. It seems you are dealing with colorkeys. 
Which are a bit different that alphas. Both give you transparency, but 
they work different. It seems you are just dealing with COLORKEY, so i'm 
guessing that's what you mean here :]


 > surf = font.render(message, 0, (level, level, level)).convert(32)

when you are rendering the font (with no smoothing here) SDL_ttf does 
create a Surface with the colorkey enabled. The way you do this in C/SDL 
is create the surface with the SDL_SRCCOLORKEY flag and then hand 
setting some values inside a C struct.

In pygame, you can also pass these C style flags to create your surface, 
but since you can't directly change the C struct values, it's not so 
useful. Working with the colorkey in pygame is best handled with the 
Surface.set_colorkey() method.

>dst = pygame.surface.Surface(newsize, SRCCOLORKEY, src)


unfortunately (or fortunately). because of the many situations where 
would want to create a new Surface. the Surface constructor has a few 
variations on the types of arguments it can accept. Your call here is 
pretty much what you want, i'd just replace the SRCCOLORKEY with a 0, 
since we will set the colorkey up in a different command.

also, there's no need to do pygame.surface.Surface, just pygame.Surface 
will do the job.

so to set the colorkey, just call
dst.set_colorkey(othersurf.get_colorkey())

after this if you check the dst.get_flags(), you'll see the SRCCOLORKEY 
flag has been set for the surface.

btw, if you call set_colorkey() with no arguments, the colorkey will be 
disabled for that Surface.


hopefully that explains things a little better. let me know if you're 
still stuck. i might be too tired to for coherency? :]



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org