pygame   documentation
||  Home  ||  Help Contents  ||
 
|| pygame || cdrom || constants || cursor || display || draw ||
|| event || font || image || joystick || key || mixer ||
|| mixer_music || mouse || movie || sndarray || surfarray || time ||
|| transform ||
 
|| CD || Channel || Clock || Font || Joystick || Movie ||
|| Overlay || Rect || Sound || Surface ||
 
|| color || cursors || sprite ||

pygame.sprite


 
This module contains a base class for sprite objects. Also several different group classes you can use to store and identify the sprites. Some of the groups can be used to draw the sprites they contain. Lastly there are a handful of collision detection functions to help you quickly find intersecting sprites in a group.
 
The way the groups are designed, it is very efficient at adding and removing sprites from groups. This makes the groups a perfect use for cataloging or tagging different sprites. instead of keeping an identifier or type as a member of a sprite class, just store the sprite in a different set of groups. this ends up being a much better way to loop through, find, and effect different sprites. It is also a very quick to test if a sprite is contained in a given group.
 
You can manage the relationship between groups and sprites from both the groups and the actual sprite classes. Both have add() and remove() functions that let you add sprites to groups and groups to sprites. Both have initializing functions that can accept a list of containers or sprites.
 
The methods to add and remove sprites from groups are smart enough to not delete sprites that aren't already part of a group, and not add sprites to a group if it already exists. You may also pass a sequence of sprites or groups to these functions and each one will be used.
 
While it is possible to design sprite and group classes that don't derive from the Sprite and AbstractGroup classes below, it is strongly recommended that you extend those when you add a Sprite or Group class.
 

AbstractGroup - (class) - A base for containers for sprites. It does everything
AbstractGroup.add - add sprite to group
AbstractGroup.clear - erase the previous position of all sprites
AbstractGroup.copy - copy a group with all the same sprites
AbstractGroup.draw - draw all sprites onto the surface
AbstractGroup.empty - remove all sprites
AbstractGroup.has - ask if group has a sprite or sprites
AbstractGroup.remove - remove sprite from group
AbstractGroup.sprites - get a list of sprites in the group
AbstractGroup.update - call update for all member sprites
Group - (class) - The basic Group class you will want to use.
GroupSingle - (class) - A group container that holds a single most recent item.
OrderedUpdates - (class) - RenderUpdates, but the sprites are drawn in the order they were added.
RenderClear - (class) - The basic Group class you will want to use.
RenderPlain - (class) - The basic Group class you will want to use.
RenderUpdates - (class) - A sprite group that's more efficient at updating.
Sprite - (class) - The base class for your visible game objects.
Sprite.add - add a sprite to container
Sprite.alive - check to see if the sprite is in any groups
Sprite.groups - list used sprite containers
Sprite.kill - remove this sprite from all groups
Sprite.remove - remove a sprite from container
groupcollide - collision detection between group and group
spritecollide - collision detection between sprite and group
spritecollideany - finds any sprites that collide

AbstractGroup
pygame.sprite.AbstractGroup()
 
AbstractGroup.add
pygame.sprite.AbstractGroup.add(sprite, list, or group, ...)
 
AbstractGroup.clear
pygame.sprite.AbstractGroup.clear(surface, bgd)
 
AbstractGroup.copy
pygame.sprite.AbstractGroup.copy()
 
AbstractGroup.draw
pygame.sprite.AbstractGroup.draw(surface)
 
AbstractGroup.empty
pygame.sprite.AbstractGroup.empty()
 
AbstractGroup.has
pygame.sprite.AbstractGroup.has(sprite or group, ...)
 
AbstractGroup.remove
pygame.sprite.AbstractGroup.remove(sprite, list, or group, ...)
 
AbstractGroup.sprites
pygame.sprite.AbstractGroup.sprites()
 
AbstractGroup.update
pygame.sprite.AbstractGroup.update(*args)
 
Group
pygame.sprite.Group()
 
GroupSingle
pygame.sprite.GroupSingle()
 
OrderedUpdates
pygame.sprite.OrderedUpdates()
 
RenderClear
pygame.sprite.RenderClear()
 
RenderPlain
pygame.sprite.RenderPlain()
 
RenderUpdates
pygame.sprite.RenderUpdates()

 
Sprite
pygame.sprite.Sprite()
 
Sprite.add
pygame.sprite.Sprite.add(group or list of of groups, ...)
 
Sprite.alive
pygame.sprite.Sprite.alive() -> bool
 
Sprite.groups
pygame.sprite.Sprite.groups() -> list of groups
 
Sprite.kill
pygame.sprite.Sprite.kill()
 
Sprite.remove
pygame.sprite.Sprite.remove(group or list of groups, ...)
 
groupcollide
pygame.sprite.groupcollide(groupa, groupb, dokilla, dokillb) -> dict
 
spritecollide
pygame.sprite.spritecollide(sprite, group, dokill) -> list
 
spritecollideany
pygame.sprite.spritecollideany(sprite, group) -> sprite