[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Cycling images
- To: pygame-users@seul.org
- Subject: Re: [pygame] Cycling images
- From: lorca <pylorca@yahoo.com.ar>
- Date: Thu, 04 Mar 2004 15:56:04 -0300
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Thu, 04 Mar 2004 13:55:47 -0500
- In-reply-to: <40400841.3050204@shinners.org>
- References: <1077937375.bd0d4fbccpaussa@myrealbox.com> <40400841.3050204@shinners.org>
- Reply-to: pygame-users@seul.org
- Sender: owner-pygame-users@seul.org
- User-agent: Mozilla Thunderbird 0.5 (X11/20040208)
mmmm, I've problem with this, the alpha channel is not working, this
function allways prints "NO alpha" although the image has the alpha
channel (and it doent shows the transparency bg, it shows in black)
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):
i = pygame.Surface(size)
i.blit(img, (0, 0), ((x, 0), size))
if i.get_alpha() is None:
print "NO alpha"
i = i.convert()
else:
print "alpha"
i = i.convert_alpha()
if colorkey is not None:
if colorkey is -1:
colorkey = i.get_at((0,0))
i.set_colorkey(colorkey, RLEACCEL)
images.append(i)
return images
Pete Shinners wrote:
This is pretty easy to do, there are a couple techniques you may want.
The main trick is that the Surface.blit() takes an optional third
argument that is the source area of the source image to use. You can
also do this by creating subsurfaces, but that may be more trouble
than worth. Here is some code Solarwolf uses to chop a strip of images
into frames.
def animstrip(img, width=0):
if not width:
width = img.get_height()
size = width, img.get_height()
images = []
for x in range(0, img.get_width(), width):
i = pygame.Surface(size)
i.blit(img, (0, 0), ((x, 0), size))
images.append(i)
return images
I've simplified this code a little. If you are dealing with colorkeys
or surface alphas you will need some extra work.