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

Re: [pygame] On walking animations...



You have the right idea.

You save all of the walking frames onto a single image. Ie: 32x32 pixel frames, with 4 frames would be 128x32.

Then when you draw your sprite, you use a source Rect() to blit one frame.

# pseudo-code
def draw():        
   w,h = 32, 32
   # give example values for current frame, and player loc.
   frame = 2 # for 4 frames, it will be 0 to 3
   x,y = (50,50)
   
   dest = Rect(x,y,w,h)
   source = Rect( frame*32, 0, w, h )

   screen.blit( sprite, dest, source )

You can use subsurf [ http://www.pygame.org/docs/ref/surface.html#Surface.subsurface ] But I found it easier to set source_rect with tilesets.
--

Jake