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

Re: [pygame] Changing the size of a sprite



I use (and recommend) a loop something like this, I think it's pretty
simple and self-explanatory.  One problem I had when I was learning was
that I didn't know that all changes to a sprite's image or rect should
be done ONLY in (or from) the sprite.update() function.

...
window = pygame.display.set_mode( (800,600) )
spriteGroup = RenderUpdates()
...
while 1:
    spriteGroup.clear( window, backgroundImage )
    spriteGroup.update()
    dirtyRects = spriteGroup.draw( window )
    pygame.display.update( dirtyRects )

> def main():
> 	[non-sprite stuff ...]
> 	sganimals=pygame.sprite.Group()
> 	[creation of sprites, which add themselves to sganimals]
> 	allsprites = pygame.sprite.RenderPlain((sganimals))
> 	while 1:
> 		[handle changes to map parameters, which
> 			affect the sprites' positions & sizes...]
> 		sganimals.update()
> 		screen.blit(screen,(0,0))	# screen is the surface
> 		allsprites.draw(screen)
> 		pygame.display.flip()
> 		
-- 
+-------------------------------------------------------------+
| Shandy Brown                               Digital Thinkery |
| shandy@geeky.net             http://www.digitalthinkery.com |
+-------------------------------------------------------------+