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

Re: [pygame] image & sprite module



azazel wrote:
> Thank you Pete, I've found your ideas very interesting, in these days I've 
> found also another way that use surfarray module(thanks to your tutorial :)
> I've created a new file image 75x75(the same of the frames) and totally
> trasparent, called "dummy", every frame I "clean" the old image with this
> dummy and then I blit the new frame on it:
> 
> def __init__(self, filename, dummyfile):
>   #load default image
>   self.imagedef = pygame.image.load(filename).convert()
>   #load dummy trasparent image
>   self.dummy = pygame.image.load(dummyfile).convert()
>   self.image = self.dummy
>   #create an array of dummy 
>   self.dummyarray = pygame.surfarray.array2d(self.dummy)
> 
> def update(self, x, y):
>   #clean the old image with dummy
>   pygame.surfarray.blit_array(self.image, self.dummyarray)
>   #blit the new frame on image
>   self.image.blit(self.imagedef, (0, 0), (x, y, 75, 75))
> 
> What do you think of this way?

i'm not sure how surfarray is helping you here. it seems you are using it
to clear the previous image? if so a call to "fill()" would work faster.
but you can do it this way without any filling or clearing. set no colorkey
on the "imagedef" and the correct one on "image". this code should have
identical results and run a little cleaner

def __init__(self, filename, dummyfile): #dummyfile unused
  self.imagedef = pygame.image.load(filename).convert()
  self.image = pygame.Surface((75, 75))
  self.image.set_colorkey(self.imagedef.get_colorkey())
  self.imagedef.set_colorkey(None)

def update(self, x, y):
  self.image.blit(self.imagedef, (0,0), (x, y, (75, 75))


also, just so you know, there is a dirt simple way to create completely
transparent images like you had, no need to load them from a file.

def create_transparent(size):
  img = pygame.Surface(size)
  img.set_colorkey(0)
  return img


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