[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] "tint" a surface?



Hi,

I guess surf.fill((10,10,10), BLEND_ADD_RGB)  except I think that's
buggy... even in pygame 1.9.1 :(

Otherwise you can create a new surface, then blit that over the top.

n = surf.convert_alpha()
# red at 50%
n.fill((255,0,0,127))
surf.blit(n, (0,0))

Well, there's probably a faster way to set the per surface
transparency... but that should work.  You can also use 8bit palette
swapping, if your image has few colors.

cheers,

On Sat, Sep 19, 2009 at 8:44 PM, Eric Pavey <warpcat@xxxxxxxxx> wrote:
> I've been searching around, trying to see if there is a 'best practice" way
> of doing this in PyGame.  Havn't found much, time to ask.  I'm used to doing
> this in Processing where it's pretty easy, so I feel like I may be missing
> something.  But don't worry, I'm a PyGame convert :)
>
> Example:
>
> A texture (.png):  donut shape, (donut pixels are white) feathered edges
> blend into alpha.  Loaded as a Surface.
> A predefined Color (say, "orange").
> I want to 'tint' my whole Surface based on the Color.  Preferably, I'd do
> this at every loop, it wouldn't be 'baked' into the image.
>
> Currently, I'm kind of hacking around this:
>
> Load my featherd donut image.
> Make a new "tint" surface based on the donut image resolution.
> Fill the "tint" surface with the given color.
> Then at each frame:
>
> Blit the tint surface to a copy of my donut surface, with
> "special_flags=BLEND_RGBA_MULT"
>
> This does work.  But seems like a lot of extra surfaces I'm making to pull
> it off.  I'd rather see (given the ability)
>
> Surface.tint(someColor)
>
> Which would simply return a new surface tinted with the given color.
> Am I missing something built-in?  Any other ideas?
>
> Thanks
>