[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Cycling images
The problem might be where you blit it from the strip to the screen. Is there any
intermediate surface?
On 4 Mar 2004 at 18:22, lorca wrote:
> to load an image, I use this function: (this function load the image
> with alpha channel)
>
> def load_image(name, colorkey=None):
> #fullname = os.path.join('data', name)
> try:
> image = pygame.image.load(name)
> except pygame.error, message:
> print 'Cannot load image:', name
> raise SystemExit, message
> # Para ver si la imagen soporta canal alpha
> if image.get_alpha() is None:
> print name
> print "NO apha"
> image = image.convert()
> else:
> print name
> print "APLHA"
> image = image.convert_alpha()
> # ######################################
> if colorkey is not None:
> #print "no none"
> if colorkey is -1:
> colorkey = image.get_at((0,0))
> image.set_colorkey(colorkey, RLEACCEL)
> return image, image.get_rect()
>
>
> but in this function the image lost the alpha channel:
>
> def animstrip(img, width=0, colorkey=None):
> if not width:
> width = img.get_height()
>
> size = width, img.get_height()
> images = []
> for x in range(0, img.get_width(), width):
> if img.get_alpha() is not None:
> i = pygame.Surface(size).convert_alpha()
> else:
> i = pygame.Surface(size).convert()
> i.blit(img, (0, 0), ((x, 0), size))
> # si se seteo colorkey toma ese color
como transparente
> if colorkey is not None:
> if colorkey is
-1:
>
# toma el color del pixel a la posicion (0,0)
>
colorkey = i.get_at((0,0))
> i.set_colorkey(colorkey,
RLEACCEL)
>
> images.append(i)
> #print images
> return images
>
>
>
> >What you want to do is check the source img, and then conditionally
> >create your new surface with or without an alpha channel. Do the
> >creation in one step:
> >
> >if img.get_alpha:
> > i = Surface(size).convert_alpha()
> >else:
> > i = Surface(size).convert()
> >
> >i.blit(yada yada)
> >
> >Regards,
> >Steve
> >
> >
> >
>
>