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

Re: [pygame] Surfaces with Transparent Backgrounds



Yeah, subsurfs rock the house.  They are also faster because they
don't copy any memory.  If you blit into img, for instance, it will be
updated in the subsurfs.  If you want to tint the sprite later, for an
effect or something, you can tint img and all of the frames will be
tinted as well.

On Fri, Aug 21, 2009 at 6:47 AM, pymike<pymike93@xxxxxxxxx> wrote:
> On Fri, Aug 21, 2009 at 7:39 AM, Rolf Sievers <rolf.sievers@xxxxxxxx> wrote:
>>
>> Hi, I don't know Pygame that well and have never used subsurfaces
>> but it it looks kinda interesting. Would you do the subsurface
>> approach in the following way?
>>
>> def load_strip(filename, width):
>>  imgs = []
>>  img = load_image(filename)
>>  for x in range(img.get_width()/width):
>>      i = img.subsurface(pygame.Rect(-x*width, 0, width, img.get_height()))
>>      imgs.append(i)
>>  return imgs
>>
>
> Oh wow, that does work. I had to remove the minus sign in -x*width, but
> otherwise it works fantastic.
>
> Thanks guys. :)
>
> --
> - pymike
>