doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
pygame.scrap.init() Initializes the scrap module. init() -> None Initialize the scrap module. Raises: pygame.error -- if unable to initialize scrap module Note The scrap module requires pygame.display.set_mode() be called before being initialized.
pygame.ref.scrap#pygame.scrap.init
pygame.scrap.lost() Indicates if the clipboard ownership has been lost by the pygame application. lost() -> bool Indicates if the clipboard ownership has been lost by the pygame application. Returns: True, if the clipboard ownership has been lost by the pygame application, False if the pygame application still owns the clipboard Return type: bool if pygame.scrap.lost(): print("The clipboard is in use by another application.")
pygame.ref.scrap#pygame.scrap.lost
pygame.scrap.put() Places data into the clipboard. put(type, data) -> None Places data for a given clipboard type into the clipboard. The data must be a string buffer. The type is a string identifying the type of data to be placed into the clipboard. This can be one of the predefined pygame.SCRAP_PBM, pygame.SCRAP_PPM, pygame.SCRAP_BMP or pygame.SCRAP_TEXT values or a user defined string identifier. Parameters: type (string) -- type identifier of the data to be placed into the clipboard data (bytes or str) -- data to be place into the clipboard (in python 3 data is a byte string and in python 2 data is a str) Raises: pygame.error -- if unable to put the data into the clipboard with open("example.bmp", "rb") as fp: pygame.scrap.put(pygame.SCRAP_BMP, fp.read()) # The image data is now on the clipboard for other applications to access # it. pygame.scrap.put(pygame.SCRAP_TEXT, b"A text to copy") pygame.scrap.put("Plain text", b"Data for user defined type 'Plain text'")
pygame.ref.scrap#pygame.scrap.put
pygame.scrap.set_mode() Sets the clipboard access mode. set_mode(mode) -> None Sets the access mode for the clipboard. This is only of interest for X11 environments where clipboard modes pygame.SCRAP_SELECTION (for mouse selections) and pygame.SCRAP_CLIPBOARD (for the clipboard) are available. Setting the mode to pygame.SCRAP_SELECTION in other environments will not change the mode from pygame.SCRAP_CLIPBOARD. Parameters: mode -- access mode, supported values are pygame.SCRAP_CLIPBOARD and pygame.SCRAP_SELECTION (pygame.SCRAP_SELECTION only has an effect when used on X11 platforms) Raises: ValueError -- if the mode parameter is not pygame.SCRAP_CLIPBOARD or pygame.SCRAP_SELECTION
pygame.ref.scrap#pygame.scrap.set_mode
pygame.set_error() set the current error message set_error(error_msg) -> None SDL maintains an internal error message. This message will usually be given to you when pygame.error() is raised, so this function will rarely be needed.
pygame.ref.pygame#pygame.set_error
pygame.sndarray.array() copy Sound samples into an array array(Sound) -> array Creates a new array for the sound data and copies the samples. The array will always be in the format returned from pygame.mixer.get_init().
pygame.ref.sndarray#pygame.sndarray.array
pygame.sndarray.get_arraytype() Gets the currently active array type. get_arraytype () -> str DEPRECATED: Returns the currently active array type. This will be a value of the get_arraytypes() tuple and indicates which type of array module is used for the array creation. New in pygame 1.8.
pygame.ref.sndarray#pygame.sndarray.get_arraytype
pygame.sndarray.get_arraytypes() Gets the array system types currently supported. get_arraytypes () -> tuple DEPRECATED: Checks, which array systems are available and returns them as a tuple of strings. The values of the tuple can be used directly in the pygame.sndarray.use_arraytype() () method. If no supported array system could be found, None will be returned. New in pygame 1.8.
pygame.ref.sndarray#pygame.sndarray.get_arraytypes
pygame.sndarray.make_sound() convert an array into a Sound object make_sound(array) -> Sound Create a new playable Sound object from an array. The mixer module must be initialized and the array format must be similar to the mixer audio format.
pygame.ref.sndarray#pygame.sndarray.make_sound
pygame.sndarray.samples() reference Sound samples into an array samples(Sound) -> array Creates a new array that directly references the samples in a Sound object. Modifying the array will change the Sound. The array will always be in the format returned from pygame.mixer.get_init().
pygame.ref.sndarray#pygame.sndarray.samples
pygame.sndarray.use_arraytype() Sets the array system to be used for sound arrays use_arraytype (arraytype) -> None DEPRECATED: Uses the requested array type for the module functions. The only supported arraytype is 'numpy'. Other values will raise ValueError.
pygame.ref.sndarray#pygame.sndarray.use_arraytype
pygame.sprite.collide_circle() Collision detection between two sprites, using circles. collide_circle(left, right) -> bool Tests for collision between two sprites, by testing to see if two circles centered on the sprites overlap. If the sprites have a "radius" attribute, that is used to create the circle, otherwise a circle is created that is big enough to completely enclose the sprites rect as given by the "rect" attribute. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "radius" attribute. New in pygame 1.8.1.
pygame.ref.sprite#pygame.sprite.collide_circle
pygame.sprite.collide_circle_ratio() Collision detection between two sprites, using circles scaled to a ratio. collide_circle_ratio(ratio) -> collided_callable A callable class that checks for collisions between two sprites, using a scaled version of the sprites radius. Is created with a floating point ratio, the instance is then intended to be passed as a collided callback function to the *collide functions. A ratio is a floating point number - 1.0 is the same size, 2.0 is twice as big, and 0.5 is half the size. The created callable tests for collision between two sprites, by testing to see if two circles centered on the sprites overlap, after scaling the circles radius by the stored ratio. If the sprites have a "radius" attribute, that is used to create the circle, otherwise a circle is created that is big enough to completely enclose the sprites rect as given by the "rect" attribute. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "radius" attribute. New in pygame 1.8.1.
pygame.ref.sprite#pygame.sprite.collide_circle_ratio
pygame.sprite.collide_mask() Collision detection between two sprites, using masks. collide_mask(sprite1, sprite2) -> (int, int) collide_mask(sprite1, sprite2) -> None Tests for collision between two sprites, by testing if their bitmasks overlap (uses pygame.mask.Mask.overlap()). If the sprites have a mask attribute, it is used as the mask, otherwise a mask is created from the sprite's image (uses pygame.mask.from_surface()). Sprites must have a rect attribute; the mask attribute is optional. The first point of collision between the masks is returned. The collision point is offset from sprite1's mask's topleft corner (which is always (0, 0)). The collision point is a position within the mask and is not related to the actual screen position of sprite1. This function is intended to be passed as a collided callback function to the group collide functions (see spritecollide(), groupcollide(), spritecollideany()). Note To increase performance, create and set a mask attibute for all sprites that will use this function to check for collisions. Otherwise, each time this function is called it will create new masks. Note A new mask needs to be recreated each time a sprite's image is changed (e.g. if a new image is used or the existing image is rotated). # Example of mask creation for a sprite. sprite.mask = pygame.mask.from_surface(sprite.image) Returns: first point of collision between the masks or None if no collision Return type: tuple(int, int) or NoneType New in pygame 1.8.0.
pygame.ref.sprite#pygame.sprite.collide_mask
pygame.sprite.collide_rect() Collision detection between two sprites, using rects. collide_rect(left, right) -> bool Tests for collision between two sprites. Uses the pygame rect colliderect function to calculate the collision. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" attributes. New in pygame 1.8.
pygame.ref.sprite#pygame.sprite.collide_rect
pygame.sprite.collide_rect_ratio() Collision detection between two sprites, using rects scaled to a ratio. collide_rect_ratio(ratio) -> collided_callable A callable class that checks for collisions between two sprites, using a scaled version of the sprites rects. Is created with a ratio, the instance is then intended to be passed as a collided callback function to the *collide functions. A ratio is a floating point number - 1.0 is the same size, 2.0 is twice as big, and 0.5 is half the size. New in pygame 1.8.1.
pygame.ref.sprite#pygame.sprite.collide_rect_ratio
pygame.sprite.DirtySprite A subclass of Sprite with more attributes and features. DirtySprite(*groups) -> DirtySprite Extra DirtySprite attributes with their default values: dirty = 1 if set to 1, it is repainted and then set to 0 again if set to 2 then it is always dirty ( repainted each frame, flag is not reset) 0 means that it is not dirty and therefore not repainted again blendmode = 0 its the special_flags argument of blit, blendmodes source_rect = None source rect to use, remember that it is relative to topleft (0,0) of self.image visible = 1 normally 1, if set to 0 it will not be repainted (you must set it dirty too to be erased from screen) layer = 0 (READONLY value, it is read when adding it to the LayeredDirty, for details see doc of LayeredDirty)
pygame.ref.sprite#pygame.sprite.DirtySprite
pygame.sprite.Group A container class to hold and manage multiple Sprite objects. Group(*sprites) -> Group A simple container for Sprite objects. This class can be inherited to create containers with more specific behaviors. The constructor takes any number of Sprite arguments to add to the Group. The group supports the following standard Python operations: in test if a Sprite is contained len the number of Sprites contained bool test if any Sprites are contained iter iterate through all the Sprites The Sprites in the Group are not ordered, so drawing and iterating the Sprites is in no particular order. sprites() list of the Sprites this Group contains sprites() -> sprite_list Return a list of all the Sprites this group contains. You can also get an iterator from the group, but you cannot iterate over a Group while modifying it. copy() duplicate the Group copy() -> Group Creates a new Group with all the same Sprites as the original. If you have subclassed Group, the new object will have the same (sub-)class as the original. This only works if the derived class's constructor takes the same arguments as the Group class's. add() add Sprites to this Group add(*sprites) -> None Add any number of Sprites to this Group. This will only add Sprites that are not already members of the Group. Each sprite argument can also be a iterator containing Sprites. remove() remove Sprites from the Group remove(*sprites) -> None Remove any number of Sprites from the Group. This will only remove Sprites that are already members of the Group. Each sprite argument can also be a iterator containing Sprites. has() test if a Group contains Sprites has(*sprites) -> bool Return True if the Group contains all of the given sprites. This is similar to using the "in" operator on the Group ("if sprite in group: ..."), which tests if a single Sprite belongs to a Group. Each sprite argument can also be a iterator containing Sprites. update() call the update method on contained Sprites update(*args, **kwargs) -> None Calls the update() method on all Sprites in the Group. The base Sprite class has an update method that takes any number of arguments and does nothing. The arguments passed to Group.update() will be passed to each Sprite. There is no way to get the return value from the Sprite.update() methods. draw() blit the Sprite images draw(Surface) -> None Draws the contained Sprites to the Surface argument. This uses the Sprite.image attribute for the source surface, and Sprite.rect for the position. The Group does not keep sprites in any order, so the draw order is arbitrary. clear() draw a background over the Sprites clear(Surface_dest, background) -> None Erases the Sprites used in the last Group.draw() call. The destination Surface is cleared by filling the drawn Sprite positions with the background. The background is usually a Surface image the same dimensions as the destination Surface. However, it can also be a callback function that takes two arguments; the destination Surface and an area to clear. The background callback function will be called several times each clear. Here is an example callback that will clear the Sprites with solid red: def clear_callback(surf, rect): color = 255, 0, 0 surf.fill(color, rect) empty() remove all Sprites empty() -> None Removes all Sprites from this Group.
pygame.ref.sprite#pygame.sprite.Group
add() add Sprites to this Group add(*sprites) -> None Add any number of Sprites to this Group. This will only add Sprites that are not already members of the Group. Each sprite argument can also be a iterator containing Sprites.
pygame.ref.sprite#pygame.sprite.Group.add
clear() draw a background over the Sprites clear(Surface_dest, background) -> None Erases the Sprites used in the last Group.draw() call. The destination Surface is cleared by filling the drawn Sprite positions with the background. The background is usually a Surface image the same dimensions as the destination Surface. However, it can also be a callback function that takes two arguments; the destination Surface and an area to clear. The background callback function will be called several times each clear. Here is an example callback that will clear the Sprites with solid red: def clear_callback(surf, rect): color = 255, 0, 0 surf.fill(color, rect)
pygame.ref.sprite#pygame.sprite.Group.clear
copy() duplicate the Group copy() -> Group Creates a new Group with all the same Sprites as the original. If you have subclassed Group, the new object will have the same (sub-)class as the original. This only works if the derived class's constructor takes the same arguments as the Group class's.
pygame.ref.sprite#pygame.sprite.Group.copy
draw() blit the Sprite images draw(Surface) -> None Draws the contained Sprites to the Surface argument. This uses the Sprite.image attribute for the source surface, and Sprite.rect for the position. The Group does not keep sprites in any order, so the draw order is arbitrary.
pygame.ref.sprite#pygame.sprite.Group.draw
empty() remove all Sprites empty() -> None Removes all Sprites from this Group.
pygame.ref.sprite#pygame.sprite.Group.empty
has() test if a Group contains Sprites has(*sprites) -> bool Return True if the Group contains all of the given sprites. This is similar to using the "in" operator on the Group ("if sprite in group: ..."), which tests if a single Sprite belongs to a Group. Each sprite argument can also be a iterator containing Sprites.
pygame.ref.sprite#pygame.sprite.Group.has
remove() remove Sprites from the Group remove(*sprites) -> None Remove any number of Sprites from the Group. This will only remove Sprites that are already members of the Group. Each sprite argument can also be a iterator containing Sprites.
pygame.ref.sprite#pygame.sprite.Group.remove
sprites() list of the Sprites this Group contains sprites() -> sprite_list Return a list of all the Sprites this group contains. You can also get an iterator from the group, but you cannot iterate over a Group while modifying it.
pygame.ref.sprite#pygame.sprite.Group.sprites
update() call the update method on contained Sprites update(*args, **kwargs) -> None Calls the update() method on all Sprites in the Group. The base Sprite class has an update method that takes any number of arguments and does nothing. The arguments passed to Group.update() will be passed to each Sprite. There is no way to get the return value from the Sprite.update() methods.
pygame.ref.sprite#pygame.sprite.Group.update
pygame.sprite.groupcollide() Find all sprites that collide between two groups. groupcollide(group1, group2, dokill1, dokill2, collided = None) -> Sprite_dict This will find collisions between all the Sprites in two groups. Collision is determined by comparing the Sprite.rect attribute of each Sprite or by using the collided function if it is not None. Every Sprite inside group1 is added to the return dictionary. The value for each item is the list of Sprites in group2 that intersect. If either dokill argument is True, the colliding Sprites will be removed from their respective Group. The collided argument is a callback function used to calculate if two sprites are colliding. It should take two sprites as values and return a bool value indicating if they are colliding. If collided is not passed, then all sprites must have a "rect" value, which is a rectangle of the sprite area, which will be used to calculate the collision.
pygame.ref.sprite#pygame.sprite.groupcollide
pygame.sprite.GroupSingle() Group container that holds a single sprite. GroupSingle(sprite=None) -> GroupSingle The GroupSingle container only holds a single Sprite. When a new Sprite is added, the old one is removed. There is a special property, GroupSingle.sprite, that accesses the Sprite that this Group contains. It can be None when the Group is empty. The property can also be assigned to add a Sprite into the GroupSingle container.
pygame.ref.sprite#pygame.sprite.GroupSingle
pygame.sprite.LayeredDirty LayeredDirty group is for DirtySprite objects. Subclasses LayeredUpdates. LayeredDirty(*spites, **kwargs) -> LayeredDirty This group requires pygame.sprite.DirtySprite or any sprite that has the following attributes: image, rect, dirty, visible, blendmode (see doc of DirtySprite). It uses the dirty flag technique and is therefore faster than the pygame.sprite.RenderUpdates if you have many static sprites. It also switches automatically between dirty rect update and full screen drawing, so you do no have to worry what would be faster. Same as for the pygame.sprite.Group. You can specify some additional attributes through kwargs: _use_update: True/False default is False _default_layer: default layer where sprites without a layer are added. _time_threshold: threshold time for switching between dirty rect mode and fullscreen mode, defaults to 1000./80 == 1000./fps New in pygame 1.8. draw() draw all sprites in the right order onto the passed surface. draw(surface, bgd=None) -> Rect_list You can pass the background too. If a background is already set, then the bgd argument has no effect. clear() used to set background clear(surface, bgd) -> None repaint_rect() repaints the given area repaint_rect(screen_rect) -> None screen_rect is in screen coordinates. set_clip() clip the area where to draw. Just pass None (default) to reset the clip set_clip(screen_rect=None) -> None get_clip() clip the area where to draw. Just pass None (default) to reset the clip get_clip() -> Rect change_layer() changes the layer of the sprite change_layer(sprite, new_layer) -> None sprite must have been added to the renderer. It is not checked. set_timing_treshold() sets the threshold in milliseconds set_timing_treshold(time_ms) -> None Default is 1000./80 where 80 is the fps I want to switch to full screen mode. This method's name is a typo and should be fixed. Raises: TypeError -- if time_ms is not int or float
pygame.ref.sprite#pygame.sprite.LayeredDirty
change_layer() changes the layer of the sprite change_layer(sprite, new_layer) -> None sprite must have been added to the renderer. It is not checked.
pygame.ref.sprite#pygame.sprite.LayeredDirty.change_layer
clear() used to set background clear(surface, bgd) -> None
pygame.ref.sprite#pygame.sprite.LayeredDirty.clear
draw() draw all sprites in the right order onto the passed surface. draw(surface, bgd=None) -> Rect_list You can pass the background too. If a background is already set, then the bgd argument has no effect.
pygame.ref.sprite#pygame.sprite.LayeredDirty.draw
get_clip() clip the area where to draw. Just pass None (default) to reset the clip get_clip() -> Rect
pygame.ref.sprite#pygame.sprite.LayeredDirty.get_clip
repaint_rect() repaints the given area repaint_rect(screen_rect) -> None screen_rect is in screen coordinates.
pygame.ref.sprite#pygame.sprite.LayeredDirty.repaint_rect
set_clip() clip the area where to draw. Just pass None (default) to reset the clip set_clip(screen_rect=None) -> None
pygame.ref.sprite#pygame.sprite.LayeredDirty.set_clip
set_timing_treshold() sets the threshold in milliseconds set_timing_treshold(time_ms) -> None Default is 1000./80 where 80 is the fps I want to switch to full screen mode. This method's name is a typo and should be fixed. Raises: TypeError -- if time_ms is not int or float
pygame.ref.sprite#pygame.sprite.LayeredDirty.set_timing_treshold
pygame.sprite.LayeredUpdates LayeredUpdates is a sprite group that handles layers and draws like OrderedUpdates. LayeredUpdates(*spites, **kwargs) -> LayeredUpdates This group is fully compatible with pygame.sprite.Sprite. You can set the default layer through kwargs using 'default_layer' and an integer for the layer. The default layer is 0. If the sprite you add has an attribute _layer then that layer will be used. If the **kwarg contains 'layer' then the sprites passed will be added to that layer (overriding the sprite.layer attribute). If neither sprite has attribute layer nor **kwarg then the default layer is used to add the sprites. New in pygame 1.8. add() add a sprite or sequence of sprites to a group add(*sprites, **kwargs) -> None If the sprite(s) have an attribute layer then that is used for the layer. If **kwargs contains 'layer' then the sprite(s) will be added to that argument (overriding the sprite layer attribute). If neither is passed then the sprite(s) will be added to the default layer. sprites() returns a ordered list of sprites (first back, last top). sprites() -> sprites draw() draw all sprites in the right order onto the passed surface. draw(surface) -> Rect_list get_sprites_at() returns a list with all sprites at that position. get_sprites_at(pos) -> colliding_sprites Bottom sprites first, top last. get_sprite() returns the sprite at the index idx from the groups sprites get_sprite(idx) -> sprite Raises IndexOutOfBounds if the idx is not within range. remove_sprites_of_layer() removes all sprites from a layer and returns them as a list. remove_sprites_of_layer(layer_nr) -> sprites layers() returns a list of layers defined (unique), sorted from bottom up. layers() -> layers change_layer() changes the layer of the sprite change_layer(sprite, new_layer) -> None sprite must have been added to the renderer. It is not checked. get_layer_of_sprite() returns the layer that sprite is currently in. get_layer_of_sprite(sprite) -> layer If the sprite is not found then it will return the default layer. get_top_layer() returns the top layer get_top_layer() -> layer get_bottom_layer() returns the bottom layer get_bottom_layer() -> layer move_to_front() brings the sprite to front layer move_to_front(sprite) -> None Brings the sprite to front, changing sprite layer to topmost layer (added at the end of that layer). move_to_back() moves the sprite to the bottom layer move_to_back(sprite) -> None Moves the sprite to the bottom layer, moving it behind all other layers and adding one additional layer. get_top_sprite() returns the topmost sprite get_top_sprite() -> Sprite get_sprites_from_layer() returns all sprites from a layer, ordered by how they where added get_sprites_from_layer(layer) -> sprites Returns all sprites from a layer, ordered by how they where added. It uses linear search and the sprites are not removed from layer. switch_layer() switches the sprites from layer1 to layer2 switch_layer(layer1_nr, layer2_nr) -> None The layers number must exist, it is not checked.
pygame.ref.sprite#pygame.sprite.LayeredUpdates
add() add a sprite or sequence of sprites to a group add(*sprites, **kwargs) -> None If the sprite(s) have an attribute layer then that is used for the layer. If **kwargs contains 'layer' then the sprite(s) will be added to that argument (overriding the sprite layer attribute). If neither is passed then the sprite(s) will be added to the default layer.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.add
change_layer() changes the layer of the sprite change_layer(sprite, new_layer) -> None sprite must have been added to the renderer. It is not checked.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.change_layer
draw() draw all sprites in the right order onto the passed surface. draw(surface) -> Rect_list
pygame.ref.sprite#pygame.sprite.LayeredUpdates.draw
get_bottom_layer() returns the bottom layer get_bottom_layer() -> layer
pygame.ref.sprite#pygame.sprite.LayeredUpdates.get_bottom_layer
get_layer_of_sprite() returns the layer that sprite is currently in. get_layer_of_sprite(sprite) -> layer If the sprite is not found then it will return the default layer.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.get_layer_of_sprite
get_sprite() returns the sprite at the index idx from the groups sprites get_sprite(idx) -> sprite Raises IndexOutOfBounds if the idx is not within range.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.get_sprite
get_sprites_at() returns a list with all sprites at that position. get_sprites_at(pos) -> colliding_sprites Bottom sprites first, top last.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.get_sprites_at
get_sprites_from_layer() returns all sprites from a layer, ordered by how they where added get_sprites_from_layer(layer) -> sprites Returns all sprites from a layer, ordered by how they where added. It uses linear search and the sprites are not removed from layer.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.get_sprites_from_layer
get_top_layer() returns the top layer get_top_layer() -> layer
pygame.ref.sprite#pygame.sprite.LayeredUpdates.get_top_layer
get_top_sprite() returns the topmost sprite get_top_sprite() -> Sprite
pygame.ref.sprite#pygame.sprite.LayeredUpdates.get_top_sprite
layers() returns a list of layers defined (unique), sorted from bottom up. layers() -> layers
pygame.ref.sprite#pygame.sprite.LayeredUpdates.layers
move_to_back() moves the sprite to the bottom layer move_to_back(sprite) -> None Moves the sprite to the bottom layer, moving it behind all other layers and adding one additional layer.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.move_to_back
move_to_front() brings the sprite to front layer move_to_front(sprite) -> None Brings the sprite to front, changing sprite layer to topmost layer (added at the end of that layer).
pygame.ref.sprite#pygame.sprite.LayeredUpdates.move_to_front
remove_sprites_of_layer() removes all sprites from a layer and returns them as a list. remove_sprites_of_layer(layer_nr) -> sprites
pygame.ref.sprite#pygame.sprite.LayeredUpdates.remove_sprites_of_layer
sprites() returns a ordered list of sprites (first back, last top). sprites() -> sprites
pygame.ref.sprite#pygame.sprite.LayeredUpdates.sprites
switch_layer() switches the sprites from layer1 to layer2 switch_layer(layer1_nr, layer2_nr) -> None The layers number must exist, it is not checked.
pygame.ref.sprite#pygame.sprite.LayeredUpdates.switch_layer
pygame.sprite.OrderedUpdates() RenderUpdates sub-class that draws Sprites in order of addition. OrderedUpdates(*spites) -> OrderedUpdates This class derives from pygame.sprite.RenderUpdates(). It maintains the order in which the Sprites were added to the Group for rendering. This makes adding and removing Sprites from the Group a little slower than regular Groups.
pygame.ref.sprite#pygame.sprite.OrderedUpdates
pygame.sprite.RenderClear Same as pygame.sprite.Group This class is an alias to pygame.sprite.Group(). It has no additional functionality.
pygame.ref.sprite#pygame.sprite.RenderClear
pygame.sprite.RenderPlain Same as pygame.sprite.Group This class is an alias to pygame.sprite.Group(). It has no additional functionality.
pygame.ref.sprite#pygame.sprite.RenderPlain
pygame.sprite.RenderUpdates Group sub-class that tracks dirty updates. RenderUpdates(*sprites) -> RenderUpdates This class is derived from pygame.sprite.Group(). It has an extended draw() method that tracks the changed areas of the screen. draw() blit the Sprite images and track changed areas draw(surface) -> Rect_list Draws all the Sprites to the surface, the same as Group.draw(). This method also returns a list of Rectangular areas on the screen that have been changed. The returned changes include areas of the screen that have been affected by previous Group.clear() calls. The returned Rect list should be passed to pygame.display.update(). This will help performance on software driven display modes. This type of updating is usually only helpful on destinations with non-animating backgrounds.
pygame.ref.sprite#pygame.sprite.RenderUpdates
draw() blit the Sprite images and track changed areas draw(surface) -> Rect_list Draws all the Sprites to the surface, the same as Group.draw(). This method also returns a list of Rectangular areas on the screen that have been changed. The returned changes include areas of the screen that have been affected by previous Group.clear() calls. The returned Rect list should be passed to pygame.display.update(). This will help performance on software driven display modes. This type of updating is usually only helpful on destinations with non-animating backgrounds.
pygame.ref.sprite#pygame.sprite.RenderUpdates.draw
pygame.sprite.Sprite Simple base class for visible game objects. Sprite(*groups) -> Sprite The base class for visible game objects. Derived classes will want to override the Sprite.update() and assign a Sprite.image and Sprite.rect attributes. The initializer can accept any number of Group instances to be added to. When subclassing the Sprite, be sure to call the base initializer before adding the Sprite to Groups. For example: class Block(pygame.sprite.Sprite): # Constructor. Pass in the color of the block, # and its x and y position def __init__(self, color, width, height): # Call the parent class (Sprite) constructor pygame.sprite.Sprite.__init__(self) # Create an image of the block, and fill it with a color. # This could also be an image loaded from the disk. self.image = pygame.Surface([width, height]) self.image.fill(color) # Fetch the rectangle object that has the dimensions of the image # Update the position of this object by setting the values of rect.x and rect.y self.rect = self.image.get_rect() update() method to control sprite behavior update(*args, **kwargs) -> None The default implementation of this method does nothing; it's just a convenient "hook" that you can override. This method is called by Group.update() with whatever arguments you give it. There is no need to use this method if not using the convenience method by the same name in the Group class. add() add the sprite to groups add(*groups) -> None Any number of Group instances can be passed as arguments. The Sprite will be added to the Groups it is not already a member of. remove() remove the sprite from groups remove(*groups) -> None Any number of Group instances can be passed as arguments. The Sprite will be removed from the Groups it is currently a member of. kill() remove the Sprite from all Groups kill() -> None The Sprite is removed from all the Groups that contain it. This won't change anything about the state of the Sprite. It is possible to continue to use the Sprite after this method has been called, including adding it to Groups. alive() does the sprite belong to any groups alive() -> bool Returns True when the Sprite belongs to one or more Groups. groups() list of Groups that contain this Sprite groups() -> group_list Return a list of all the Groups that contain this Sprite.
pygame.ref.sprite#pygame.sprite.Sprite
add() add the sprite to groups add(*groups) -> None Any number of Group instances can be passed as arguments. The Sprite will be added to the Groups it is not already a member of.
pygame.ref.sprite#pygame.sprite.Sprite.add
alive() does the sprite belong to any groups alive() -> bool Returns True when the Sprite belongs to one or more Groups.
pygame.ref.sprite#pygame.sprite.Sprite.alive
groups() list of Groups that contain this Sprite groups() -> group_list Return a list of all the Groups that contain this Sprite.
pygame.ref.sprite#pygame.sprite.Sprite.groups
kill() remove the Sprite from all Groups kill() -> None The Sprite is removed from all the Groups that contain it. This won't change anything about the state of the Sprite. It is possible to continue to use the Sprite after this method has been called, including adding it to Groups.
pygame.ref.sprite#pygame.sprite.Sprite.kill
remove() remove the sprite from groups remove(*groups) -> None Any number of Group instances can be passed as arguments. The Sprite will be removed from the Groups it is currently a member of.
pygame.ref.sprite#pygame.sprite.Sprite.remove
update() method to control sprite behavior update(*args, **kwargs) -> None The default implementation of this method does nothing; it's just a convenient "hook" that you can override. This method is called by Group.update() with whatever arguments you give it. There is no need to use this method if not using the convenience method by the same name in the Group class.
pygame.ref.sprite#pygame.sprite.Sprite.update
pygame.sprite.spritecollide() Find sprites in a group that intersect another sprite. spritecollide(sprite, group, dokill, collided = None) -> Sprite_list Return a list containing all Sprites in a Group that intersect with another Sprite. Intersection is determined by comparing the Sprite.rect attribute of each Sprite. The dokill argument is a bool. If set to True, all Sprites that collide will be removed from the Group. The collided argument is a callback function used to calculate if two sprites are colliding. it should take two sprites as values, and return a bool value indicating if they are colliding. If collided is not passed, all sprites must have a "rect" value, which is a rectangle of the sprite area, which will be used to calculate the collision. collided callables: collide_rect, collide_rect_ratio, collide_circle, collide_circle_ratio, collide_mask Example: # See if the Sprite block has collided with anything in the Group block_list # The True flag will remove the sprite in block_list blocks_hit_list = pygame.sprite.spritecollide(player, block_list, True) # Check the list of colliding sprites, and add one to the score for each one for block in blocks_hit_list: score +=1
pygame.ref.sprite#pygame.sprite.spritecollide
pygame.sprite.spritecollideany() Simple test if a sprite intersects anything in a group. spritecollideany(sprite, group, collided = None) -> Sprite Collision with the returned sprite. spritecollideany(sprite, group, collided = None) -> None No collision If the sprite collides with any single sprite in the group, a single sprite from the group is returned. On no collision None is returned. If you don't need all the features of the pygame.sprite.spritecollide() function, this function will be a bit quicker. The collided argument is a callback function used to calculate if two sprites are colliding. It should take two sprites as values and return a bool value indicating if they are colliding. If collided is not passed, then all sprites must have a "rect" value, which is a rectangle of the sprite area, which will be used to calculate the collision.
pygame.ref.sprite#pygame.sprite.spritecollideany
pygame.Surface pygame object for representing images Surface((width, height), flags=0, depth=0, masks=None) -> Surface Surface((width, height), flags=0, Surface) -> Surface A pygame Surface is used to represent any image. The Surface has a fixed resolution and pixel format. Surfaces with 8-bit pixels use a color palette to map to 24-bit color. Call pygame.Surface() to create a new image object. The Surface will be cleared to all black. The only required arguments are the sizes. With no additional arguments, the Surface will be created in a format that best matches the display Surface. The pixel format can be controlled by passing the bit depth or an existing Surface. The flags argument is a bitmask of additional features for the surface. You can pass any combination of these flags: HWSURFACE creates the image in video memory SRCALPHA the pixel format will include a per-pixel alpha Both flags are only a request, and may not be possible for all displays and formats. Advance users can combine a set of bitmasks with a depth value. The masks are a set of 4 integers representing which bits in a pixel will represent each color. Normal Surfaces should not require the masks argument. Surfaces can have many extra attributes like alpha planes, colorkeys, source rectangle clipping. These functions mainly effect how the Surface is blitted to other Surfaces. The blit routines will attempt to use hardware acceleration when possible, otherwise they will use highly optimized software blitting methods. There are three types of transparency supported in pygame: colorkeys, surface alphas, and pixel alphas. Surface alphas can be mixed with colorkeys, but an image with per pixel alphas cannot use the other modes. Colorkey transparency makes a single color value transparent. Any pixels matching the colorkey will not be drawn. The surface alpha value is a single value that changes the transparency for the entire image. A surface alpha of 255 is opaque, and a value of 0 is completely transparent. Per pixel alphas are different because they store a transparency value for every pixel. This allows for the most precise transparency effects, but it also the slowest. Per pixel alphas cannot be mixed with surface alpha and colorkeys. There is support for pixel access for the Surfaces. Pixel access on hardware surfaces is slow and not recommended. Pixels can be accessed using the get_at() and set_at() functions. These methods are fine for simple access, but will be considerably slow when doing of pixel work with them. If you plan on doing a lot of pixel level work, it is recommended to use a pygame.PixelArray, which gives an array like view of the surface. For involved mathematical manipulations try the pygame.surfarray module (It's quite quick, but requires NumPy.) Any functions that directly access a surface's pixel data will need that surface to be lock()'ed. These functions can lock() and unlock() the surfaces themselves without assistance. But, if a function will be called many times, there will be a lot of overhead for multiple locking and unlocking of the surface. It is best to lock the surface manually before making the function call many times, and then unlocking when you are finished. All functions that need a locked surface will say so in their docs. Remember to leave the Surface locked only while necessary. Surface pixels are stored internally as a single number that has all the colors encoded into it. Use the map_rgb() and unmap_rgb() to convert between individual red, green, and blue values into a packed integer for that Surface. Surfaces can also reference sections of other Surfaces. These are created with the subsurface() method. Any change to either Surface will effect the other. Each Surface contains a clipping area. By default the clip area covers the entire Surface. If it is changed, all drawing operations will only effect the smaller area. blit() draw one image onto another blit(source, dest, area=None, special_flags=0) -> Rect Draws a source Surface onto this Surface. The draw can be positioned with the dest argument. The dest argument can either be a pair of coordinates representing the position of the upper left corner of the blit or a Rect, where the upper left corner of the rectangle will be used as the position for the blit. The size of the destination rectangle does not effect the blit. An optional area rectangle can be passed as well. This represents a smaller portion of the source Surface to draw. New in pygame 1.8: Optional special_flags: BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX. New in pygame 1.8.1: Optional special_flags: BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAX BLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX. New in pygame 1.9.2: Optional special_flags: BLEND_PREMULTIPLIED New in pygame 2.0.0: Optional special_flags: BLEND_ALPHA_SDL2 - Uses the SDL2 blitter for alpha blending, this gives different results than the default blitter, which is modelled after SDL1, due to different approximations used for the alpha blending formula. The SDL2 blitter also supports RLE on alpha blended surfaces which the pygame one does not. The return rectangle is the area of the affected pixels, excluding any pixels outside the destination Surface, or outside the clipping area. Pixel alphas will be ignored when blitting to an 8 bit Surface. For a surface with colorkey or blanket alpha, a blit to self may give slightly different colors than a non self-blit. blits() draw many images onto another blits(blit_sequence=(source, dest), ...), doreturn=1) -> [Rect, ...] or None blits((source, dest, area), ...)) -> [Rect, ...] blits((source, dest, area, special_flags), ...)) -> [Rect, ...] Draws many surfaces onto this Surface. It takes a sequence as input, with each of the elements corresponding to the ones of blit(). It needs at minimum a sequence of (source, dest). Parameters: blit_sequence -- a sequence of surfaces and arguments to blit them, they correspond to the blit() arguments doreturn -- if True, return a list of rects of the areas changed, otherwise return None Returns: a list of rects of the areas changed if doreturn is True, otherwise None Return type: list or None New in pygame 1.9.4. convert() change the pixel format of an image convert(Surface=None) -> Surface convert(depth, flags=0) -> Surface convert(masks, flags=0) -> Surface Creates a new copy of the Surface with the pixel format changed. The new pixel format can be determined from another existing Surface. Otherwise depth, flags, and masks arguments can be used, similar to the pygame.Surface() call. If no arguments are passed the new Surface will have the same pixel format as the display Surface. This is always the fastest format for blitting. It is a good idea to convert all Surfaces before they are blitted many times. The converted Surface will have no pixel alphas. They will be stripped if the original had them. See convert_alpha() for preserving or creating per-pixel alphas. The new copy will have the same class as the copied surface. This lets as Surface subclass inherit this method without the need to override, unless subclass specific instance attributes also need copying. convert_alpha() change the pixel format of an image including per pixel alphas convert_alpha(Surface) -> Surface convert_alpha() -> Surface Creates a new copy of the surface with the desired pixel format. The new surface will be in a format suited for quick blitting to the given format with per pixel alpha. If no surface is given, the new surface will be optimized for blitting to the current display. Unlike the convert() method, the pixel format for the new image will not be exactly the same as the requested source, but it will be optimized for fast alpha blitting to the destination. As with convert() the returned surface has the same class as the converted surface. copy() create a new copy of a Surface copy() -> Surface Makes a duplicate copy of a Surface. The new surface will have the same pixel formats, color palettes, transparency settings, and class as the original. If a Surface subclass also needs to copy any instance specific attributes then it should override copy(). fill() fill Surface with a solid color fill(color, rect=None, special_flags=0) -> Rect Fill the Surface with a solid color. If no rect argument is given the entire Surface will be filled. The rect argument will limit the fill to a specific area. The fill will also be contained by the Surface clip area. The color argument can be either a RGB sequence, a RGBA sequence or a mapped color index. If using RGBA, the Alpha (A part of RGBA) is ignored unless the surface uses per pixel alpha (Surface has the SRCALPHA flag). New in pygame 1.8: Optional special_flags: BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX. New in pygame 1.8.1: Optional special_flags: BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAX BLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX. This will return the affected Surface area. scroll() Shift the surface image in place scroll(dx=0, dy=0) -> None Move the image by dx pixels right and dy pixels down. dx and dy may be negative for left and up scrolls respectively. Areas of the surface that are not overwritten retain their original pixel values. Scrolling is contained by the Surface clip area. It is safe to have dx and dy values that exceed the surface size. New in pygame 1.9. set_colorkey() Set the transparent colorkey set_colorkey(Color, flags=0) -> None set_colorkey(None) -> None Set the current color key for the Surface. When blitting this Surface onto a destination, any pixels that have the same color as the colorkey will be transparent. The color can be an RGB color or a mapped color integer. If None is passed, the colorkey will be unset. The colorkey will be ignored if the Surface is formatted to use per pixel alpha values. The colorkey can be mixed with the full Surface alpha value. The optional flags argument can be set to pygame.RLEACCEL to provide better performance on non accelerated displays. An RLEACCEL Surface will be slower to modify, but quicker to blit as a source. get_colorkey() Get the current transparent colorkey get_colorkey() -> RGB or None Return the current colorkey value for the Surface. If the colorkey is not set then None is returned. set_alpha() set the alpha value for the full Surface image set_alpha(value, flags=0) -> None set_alpha(None) -> None Set the current alpha value for the Surface. When blitting this Surface onto a destination, the pixels will be drawn slightly transparent. The alpha value is an integer from 0 to 255, 0 is fully transparent and 255 is fully opaque. If None is passed for the alpha value, then alpha blending will be disabled, including per-pixel alpha. This value is different than the per pixel Surface alpha. For a surface with per pixel alpha, blanket alpha is ignored and None is returned. Changed in pygame 2.0: per-surface alpha can be combined with per-pixel alpha. The optional flags argument can be set to pygame.RLEACCEL to provide better performance on non accelerated displays. An RLEACCEL Surface will be slower to modify, but quicker to blit as a source. get_alpha() get the current Surface transparency value get_alpha() -> int_value Return the current alpha value for the Surface. lock() lock the Surface memory for pixel access lock() -> None Lock the pixel data of a Surface for access. On accelerated Surfaces, the pixel data may be stored in volatile video memory or nonlinear compressed forms. When a Surface is locked the pixel memory becomes available to access by regular software. Code that reads or writes pixel values will need the Surface to be locked. Surfaces should not remain locked for more than necessary. A locked Surface can often not be displayed or managed by pygame. Not all Surfaces require locking. The mustlock() method can determine if it is actually required. There is no performance penalty for locking and unlocking a Surface that does not need it. All pygame functions will automatically lock and unlock the Surface data as needed. If a section of code is going to make calls that will repeatedly lock and unlock the Surface many times, it can be helpful to wrap the block inside a lock and unlock pair. It is safe to nest locking and unlocking calls. The surface will only be unlocked after the final lock is released. unlock() unlock the Surface memory from pixel access unlock() -> None Unlock the Surface pixel data after it has been locked. The unlocked Surface can once again be drawn and managed by pygame. See the lock() documentation for more details. All pygame functions will automatically lock and unlock the Surface data as needed. If a section of code is going to make calls that will repeatedly lock and unlock the Surface many times, it can be helpful to wrap the block inside a lock and unlock pair. It is safe to nest locking and unlocking calls. The surface will only be unlocked after the final lock is released. mustlock() test if the Surface requires locking mustlock() -> bool Returns True if the Surface is required to be locked to access pixel data. Usually pure software Surfaces do not require locking. This method is rarely needed, since it is safe and quickest to just lock all Surfaces as needed. All pygame functions will automatically lock and unlock the Surface data as needed. If a section of code is going to make calls that will repeatedly lock and unlock the Surface many times, it can be helpful to wrap the block inside a lock and unlock pair. get_locked() test if the Surface is current locked get_locked() -> bool Returns True when the Surface is locked. It doesn't matter how many times the Surface is locked. get_locks() Gets the locks for the Surface get_locks() -> tuple Returns the currently existing locks for the Surface. get_at() get the color value at a single pixel get_at((x, y)) -> Color Return a copy of the RGBA Color value at the given pixel. If the Surface has no per pixel alpha, then the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface an IndexError exception will be raised. Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation. It is better to use methods which operate on many pixels at a time like with the blit, fill and draw methods - or by using pygame.surfarray/pygame.PixelArray. This function will temporarily lock and unlock the Surface as needed. New in pygame 1.9: Returning a Color instead of tuple. Use tuple(surf.get_at((x,y))) if you want a tuple, and not a Color. This should only matter if you want to use the color as a key in a dict. set_at() set the color value for a single pixel set_at((x, y), Color) -> None Set the RGBA or mapped integer color value for a single pixel. If the Surface does not have per pixel alphas, the alpha value is ignored. Setting pixels outside the Surface area or outside the Surface clipping will have no effect. Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation. This function will temporarily lock and unlock the Surface as needed. get_at_mapped() get the mapped color value at a single pixel get_at_mapped((x, y)) -> Color Return the integer value of the given pixel. If the pixel position is outside the area of the Surface an IndexError exception will be raised. This method is intended for pygame unit testing. It unlikely has any use in an application. This function will temporarily lock and unlock the Surface as needed. New in pygame 1.9.2. get_palette() get the color index palette for an 8-bit Surface get_palette() -> [RGB, RGB, RGB, ...] Return a list of up to 256 color elements that represent the indexed colors used in an 8-bit Surface. The returned list is a copy of the palette, and changes will have no effect on the Surface. Returning a list of Color(with length 3) instances instead of tuples. New in pygame 1.9. get_palette_at() get the color for a single entry in a palette get_palette_at(index) -> RGB Returns the red, green, and blue color values for a single index in a Surface palette. The index should be a value from 0 to 255. New in pygame 1.9: Returning Color(with length 3) instance instead of a tuple. set_palette() set the color palette for an 8-bit Surface set_palette([RGB, RGB, RGB, ...]) -> None Set the full palette for an 8-bit Surface. This will replace the colors in the existing palette. A partial palette can be passed and only the first colors in the original palette will be changed. This function has no effect on a Surface with more than 8-bits per pixel. set_palette_at() set the color for a single index in an 8-bit Surface palette set_palette_at(index, RGB) -> None Set the palette value for a single entry in a Surface palette. The index should be a value from 0 to 255. This function has no effect on a Surface with more than 8-bits per pixel. map_rgb() convert a color into a mapped color value map_rgb(Color) -> mapped_int Convert an RGBA color into the mapped integer value for this Surface. The returned integer will contain no more bits than the bit depth of the Surface. Mapped color values are not often used inside pygame, but can be passed to most functions that require a Surface and a color. See the Surface object documentation for more information about colors and pixel formats. unmap_rgb() convert a mapped integer color value into a Color unmap_rgb(mapped_int) -> Color Convert an mapped integer color into the RGB color components for this Surface. Mapped color values are not often used inside pygame, but can be passed to most functions that require a Surface and a color. See the Surface object documentation for more information about colors and pixel formats. set_clip() set the current clipping area of the Surface set_clip(rect) -> None set_clip(None) -> None Each Surface has an active clipping area. This is a rectangle that represents the only pixels on the Surface that can be modified. If None is passed for the rectangle the full Surface will be available for changes. The clipping area is always restricted to the area of the Surface itself. If the clip rectangle is too large it will be shrunk to fit inside the Surface. get_clip() get the current clipping area of the Surface get_clip() -> Rect Return a rectangle of the current clipping area. The Surface will always return a valid rectangle that will never be outside the bounds of the image. If the Surface has had None set for the clipping area, the Surface will return a rectangle with the full area of the Surface. subsurface() create a new surface that references its parent subsurface(Rect) -> Surface Returns a new Surface that shares its pixels with its new parent. The new Surface is considered a child of the original. Modifications to either Surface pixels will effect each other. Surface information like clipping area and color keys are unique to each Surface. The new Surface will inherit the palette, color key, and alpha settings from its parent. It is possible to have any number of subsurfaces and subsubsurfaces on the parent. It is also possible to subsurface the display Surface if the display mode is not hardware accelerated. See get_offset() and get_parent() to learn more about the state of a subsurface. A subsurface will have the same class as the parent surface. get_parent() find the parent of a subsurface get_parent() -> Surface Returns the parent Surface of a subsurface. If this is not a subsurface then None will be returned. get_abs_parent() find the top level parent of a subsurface get_abs_parent() -> Surface Returns the parent Surface of a subsurface. If this is not a subsurface then this surface will be returned. get_offset() find the position of a child subsurface inside a parent get_offset() -> (x, y) Get the offset position of a child subsurface inside of a parent. If the Surface is not a subsurface this will return (0, 0). get_abs_offset() find the absolute position of a child subsurface inside its top level parent get_abs_offset() -> (x, y) Get the offset position of a child subsurface inside of its top level parent Surface. If the Surface is not a subsurface this will return (0, 0). get_size() get the dimensions of the Surface get_size() -> (width, height) Return the width and height of the Surface in pixels. get_width() get the width of the Surface get_width() -> width Return the width of the Surface in pixels. get_height() get the height of the Surface get_height() -> height Return the height of the Surface in pixels. get_rect() get the rectangular area of the Surface get_rect(**kwargs) -> Rect Returns a new rectangle covering the entire surface. This rectangle will always start at (0, 0) with a width and height the same size as the image. You can pass keyword argument values to this function. These named values will be applied to the attributes of the Rect before it is returned. An example would be mysurf.get_rect(center=(100, 100)) to create a rectangle for the Surface centered at a given position. get_bitsize() get the bit depth of the Surface pixel format get_bitsize() -> int Returns the number of bits used to represent each pixel. This value may not exactly fill the number of bytes used per pixel. For example a 15 bit Surface still requires a full 2 bytes. get_bytesize() get the bytes used per Surface pixel get_bytesize() -> int Return the number of bytes used per pixel. get_flags() get the additional flags used for the Surface get_flags() -> int Returns a set of current Surface features. Each feature is a bit in the flags bitmask. Typical flags are HWSURFACE, RLEACCEL, SRCALPHA, and SRCCOLORKEY. Here is a more complete list of flags. A full list can be found in SDL_video.h SWSURFACE 0x00000000 # Surface is in system memory HWSURFACE 0x00000001 # Surface is in video memory ASYNCBLIT 0x00000004 # Use asynchronous blits if possible Available for pygame.display.set_mode() ANYFORMAT 0x10000000 # Allow any video depth/pixel-format HWPALETTE 0x20000000 # Surface has exclusive palette DOUBLEBUF 0x40000000 # Set up double-buffered video mode FULLSCREEN 0x80000000 # Surface is a full screen display OPENGL 0x00000002 # Create an OpenGL rendering context OPENGLBLIT 0x0000000A # OBSOLETE. Create an OpenGL rendering context and use it for blitting. RESIZABLE 0x00000010 # This video mode may be resized NOFRAME 0x00000020 # No window caption or edge frame Used internally (read-only) HWACCEL 0x00000100 # Blit uses hardware acceleration SRCCOLORKEY 0x00001000 # Blit uses a source color key RLEACCELOK 0x00002000 # Private flag RLEACCEL 0x00004000 # Surface is RLE encoded SRCALPHA 0x00010000 # Blit uses source alpha blending PREALLOC 0x01000000 # Surface uses preallocated memory get_pitch() get the number of bytes used per Surface row get_pitch() -> int Return the number of bytes separating each row in the Surface. Surfaces in video memory are not always linearly packed. Subsurfaces will also have a larger pitch than their real width. This value is not needed for normal pygame usage. get_masks() the bitmasks needed to convert between a color and a mapped integer get_masks() -> (R, G, B, A) Returns the bitmasks used to isolate each color in a mapped integer. This value is not needed for normal pygame usage. set_masks() set the bitmasks needed to convert between a color and a mapped integer set_masks((r,g,b,a)) -> None This is not needed for normal pygame usage. Note In SDL2, the masks are read-only and accordingly this method will raise an AttributeError if called. New in pygame 1.8.1. get_shifts() the bit shifts needed to convert between a color and a mapped integer get_shifts() -> (R, G, B, A) Returns the pixel shifts need to convert between each color and a mapped integer. This value is not needed for normal pygame usage. set_shifts() sets the bit shifts needed to convert between a color and a mapped integer set_shifts((r,g,b,a)) -> None This is not needed for normal pygame usage. Note In SDL2, the shifts are read-only and accordingly this method will raise an AttributeError if called. New in pygame 1.8.1. get_losses() the significant bits used to convert between a color and a mapped integer get_losses() -> (R, G, B, A) Return the least significant number of bits stripped from each color in a mapped integer. This value is not needed for normal pygame usage. get_bounding_rect() find the smallest rect containing data get_bounding_rect(min_alpha = 1) -> Rect Returns the smallest rectangular region that contains all the pixels in the surface that have an alpha value greater than or equal to the minimum alpha value. This function will temporarily lock and unlock the Surface as needed. New in pygame 1.8. get_view() return a buffer view of the Surface's pixels. get_view(<kind>='2') -> BufferProxy Return an object which exports a surface's internal pixel buffer as a C level array struct, Python level array interface or a C level buffer interface. The pixel buffer is writeable. The new buffer protocol is supported for Python 2.6 and up in CPython. The old buffer protocol is also supported for Python 2.x. The old buffer data is in one segment for kind '0', multi-segment for other buffer view kinds. The kind argument is the length 1 string '0', '1', '2', '3', 'r', 'g', 'b', or 'a'. The letters are case insensitive; 'A' will work as well. The argument can be either a Unicode or byte (char) string. The default is '2'. '0' returns a contiguous unstructured bytes view. No surface shape information is given. A ValueError is raised if the surface's pixels are discontinuous. '1' returns a (surface-width * surface-height) array of continuous pixels. A ValueError is raised if the surface pixels are discontinuous. '2' returns a (surface-width, surface-height) array of raw pixels. The pixels are surface-bytesize-d unsigned integers. The pixel format is surface specific. The 3 byte unsigned integers of 24 bit surfaces are unlikely accepted by anything other than other pygame functions. '3' returns a (surface-width, surface-height, 3) array of RGB color components. Each of the red, green, and blue components are unsigned bytes. Only 24-bit and 32-bit surfaces are supported. The color components must be in either RGB or BGR order within the pixel. 'r' for red, 'g' for green, 'b' for blue, and 'a' for alpha return a (surface-width, surface-height) view of a single color component within a surface: a color plane. Color components are unsigned bytes. Both 24-bit and 32-bit surfaces support 'r', 'g', and 'b'. Only 32-bit surfaces with SRCALPHA support 'a'. The surface is locked only when an exposed interface is accessed. For new buffer interface accesses, the surface is unlocked once the last buffer view is released. For array interface and old buffer interface accesses, the surface remains locked until the BufferProxy object is released. New in pygame 1.9.2. get_buffer() acquires a buffer object for the pixels of the Surface. get_buffer() -> BufferProxy Return a buffer object for the pixels of the Surface. The buffer can be used for direct pixel access and manipulation. Surface pixel data is represented as an unstructured block of memory, with a start address and length in bytes. The data need not be contiguous. Any gaps are included in the length, but otherwise ignored. This method implicitly locks the Surface. The lock will be released when the returned pygame.BufferProxy object is garbage collected. New in pygame 1.8. _pixels_address pixel buffer address _pixels_address -> int The starting address of the surface's raw pixel bytes. New in pygame 1.9.2.
pygame.ref.surface
_pixels_address pixel buffer address _pixels_address -> int The starting address of the surface's raw pixel bytes. New in pygame 1.9.2.
pygame.ref.surface#pygame.Surface._pixels_address
blit() draw one image onto another blit(source, dest, area=None, special_flags=0) -> Rect Draws a source Surface onto this Surface. The draw can be positioned with the dest argument. The dest argument can either be a pair of coordinates representing the position of the upper left corner of the blit or a Rect, where the upper left corner of the rectangle will be used as the position for the blit. The size of the destination rectangle does not effect the blit. An optional area rectangle can be passed as well. This represents a smaller portion of the source Surface to draw. New in pygame 1.8: Optional special_flags: BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX. New in pygame 1.8.1: Optional special_flags: BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAX BLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX. New in pygame 1.9.2: Optional special_flags: BLEND_PREMULTIPLIED New in pygame 2.0.0: Optional special_flags: BLEND_ALPHA_SDL2 - Uses the SDL2 blitter for alpha blending, this gives different results than the default blitter, which is modelled after SDL1, due to different approximations used for the alpha blending formula. The SDL2 blitter also supports RLE on alpha blended surfaces which the pygame one does not. The return rectangle is the area of the affected pixels, excluding any pixels outside the destination Surface, or outside the clipping area. Pixel alphas will be ignored when blitting to an 8 bit Surface. For a surface with colorkey or blanket alpha, a blit to self may give slightly different colors than a non self-blit.
pygame.ref.surface#pygame.Surface.blit
blits() draw many images onto another blits(blit_sequence=(source, dest), ...), doreturn=1) -> [Rect, ...] or None blits((source, dest, area), ...)) -> [Rect, ...] blits((source, dest, area, special_flags), ...)) -> [Rect, ...] Draws many surfaces onto this Surface. It takes a sequence as input, with each of the elements corresponding to the ones of blit(). It needs at minimum a sequence of (source, dest). Parameters: blit_sequence -- a sequence of surfaces and arguments to blit them, they correspond to the blit() arguments doreturn -- if True, return a list of rects of the areas changed, otherwise return None Returns: a list of rects of the areas changed if doreturn is True, otherwise None Return type: list or None New in pygame 1.9.4.
pygame.ref.surface#pygame.Surface.blits
convert() change the pixel format of an image convert(Surface=None) -> Surface convert(depth, flags=0) -> Surface convert(masks, flags=0) -> Surface Creates a new copy of the Surface with the pixel format changed. The new pixel format can be determined from another existing Surface. Otherwise depth, flags, and masks arguments can be used, similar to the pygame.Surface() call. If no arguments are passed the new Surface will have the same pixel format as the display Surface. This is always the fastest format for blitting. It is a good idea to convert all Surfaces before they are blitted many times. The converted Surface will have no pixel alphas. They will be stripped if the original had them. See convert_alpha() for preserving or creating per-pixel alphas. The new copy will have the same class as the copied surface. This lets as Surface subclass inherit this method without the need to override, unless subclass specific instance attributes also need copying.
pygame.ref.surface#pygame.Surface.convert
convert_alpha() change the pixel format of an image including per pixel alphas convert_alpha(Surface) -> Surface convert_alpha() -> Surface Creates a new copy of the surface with the desired pixel format. The new surface will be in a format suited for quick blitting to the given format with per pixel alpha. If no surface is given, the new surface will be optimized for blitting to the current display. Unlike the convert() method, the pixel format for the new image will not be exactly the same as the requested source, but it will be optimized for fast alpha blitting to the destination. As with convert() the returned surface has the same class as the converted surface.
pygame.ref.surface#pygame.Surface.convert_alpha
copy() create a new copy of a Surface copy() -> Surface Makes a duplicate copy of a Surface. The new surface will have the same pixel formats, color palettes, transparency settings, and class as the original. If a Surface subclass also needs to copy any instance specific attributes then it should override copy().
pygame.ref.surface#pygame.Surface.copy
fill() fill Surface with a solid color fill(color, rect=None, special_flags=0) -> Rect Fill the Surface with a solid color. If no rect argument is given the entire Surface will be filled. The rect argument will limit the fill to a specific area. The fill will also be contained by the Surface clip area. The color argument can be either a RGB sequence, a RGBA sequence or a mapped color index. If using RGBA, the Alpha (A part of RGBA) is ignored unless the surface uses per pixel alpha (Surface has the SRCALPHA flag). New in pygame 1.8: Optional special_flags: BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX. New in pygame 1.8.1: Optional special_flags: BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAX BLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX. This will return the affected Surface area.
pygame.ref.surface#pygame.Surface.fill
get_abs_offset() find the absolute position of a child subsurface inside its top level parent get_abs_offset() -> (x, y) Get the offset position of a child subsurface inside of its top level parent Surface. If the Surface is not a subsurface this will return (0, 0).
pygame.ref.surface#pygame.Surface.get_abs_offset
get_abs_parent() find the top level parent of a subsurface get_abs_parent() -> Surface Returns the parent Surface of a subsurface. If this is not a subsurface then this surface will be returned.
pygame.ref.surface#pygame.Surface.get_abs_parent
get_alpha() get the current Surface transparency value get_alpha() -> int_value Return the current alpha value for the Surface.
pygame.ref.surface#pygame.Surface.get_alpha
get_at() get the color value at a single pixel get_at((x, y)) -> Color Return a copy of the RGBA Color value at the given pixel. If the Surface has no per pixel alpha, then the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface an IndexError exception will be raised. Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation. It is better to use methods which operate on many pixels at a time like with the blit, fill and draw methods - or by using pygame.surfarray/pygame.PixelArray. This function will temporarily lock and unlock the Surface as needed. New in pygame 1.9: Returning a Color instead of tuple. Use tuple(surf.get_at((x,y))) if you want a tuple, and not a Color. This should only matter if you want to use the color as a key in a dict.
pygame.ref.surface#pygame.Surface.get_at
get_at_mapped() get the mapped color value at a single pixel get_at_mapped((x, y)) -> Color Return the integer value of the given pixel. If the pixel position is outside the area of the Surface an IndexError exception will be raised. This method is intended for pygame unit testing. It unlikely has any use in an application. This function will temporarily lock and unlock the Surface as needed. New in pygame 1.9.2.
pygame.ref.surface#pygame.Surface.get_at_mapped
get_bitsize() get the bit depth of the Surface pixel format get_bitsize() -> int Returns the number of bits used to represent each pixel. This value may not exactly fill the number of bytes used per pixel. For example a 15 bit Surface still requires a full 2 bytes.
pygame.ref.surface#pygame.Surface.get_bitsize
get_bounding_rect() find the smallest rect containing data get_bounding_rect(min_alpha = 1) -> Rect Returns the smallest rectangular region that contains all the pixels in the surface that have an alpha value greater than or equal to the minimum alpha value. This function will temporarily lock and unlock the Surface as needed. New in pygame 1.8.
pygame.ref.surface#pygame.Surface.get_bounding_rect
get_buffer() acquires a buffer object for the pixels of the Surface. get_buffer() -> BufferProxy Return a buffer object for the pixels of the Surface. The buffer can be used for direct pixel access and manipulation. Surface pixel data is represented as an unstructured block of memory, with a start address and length in bytes. The data need not be contiguous. Any gaps are included in the length, but otherwise ignored. This method implicitly locks the Surface. The lock will be released when the returned pygame.BufferProxy object is garbage collected. New in pygame 1.8.
pygame.ref.surface#pygame.Surface.get_buffer
get_bytesize() get the bytes used per Surface pixel get_bytesize() -> int Return the number of bytes used per pixel.
pygame.ref.surface#pygame.Surface.get_bytesize
get_clip() get the current clipping area of the Surface get_clip() -> Rect Return a rectangle of the current clipping area. The Surface will always return a valid rectangle that will never be outside the bounds of the image. If the Surface has had None set for the clipping area, the Surface will return a rectangle with the full area of the Surface.
pygame.ref.surface#pygame.Surface.get_clip
get_colorkey() Get the current transparent colorkey get_colorkey() -> RGB or None Return the current colorkey value for the Surface. If the colorkey is not set then None is returned.
pygame.ref.surface#pygame.Surface.get_colorkey
get_flags() get the additional flags used for the Surface get_flags() -> int Returns a set of current Surface features. Each feature is a bit in the flags bitmask. Typical flags are HWSURFACE, RLEACCEL, SRCALPHA, and SRCCOLORKEY. Here is a more complete list of flags. A full list can be found in SDL_video.h SWSURFACE 0x00000000 # Surface is in system memory HWSURFACE 0x00000001 # Surface is in video memory ASYNCBLIT 0x00000004 # Use asynchronous blits if possible Available for pygame.display.set_mode() ANYFORMAT 0x10000000 # Allow any video depth/pixel-format HWPALETTE 0x20000000 # Surface has exclusive palette DOUBLEBUF 0x40000000 # Set up double-buffered video mode FULLSCREEN 0x80000000 # Surface is a full screen display OPENGL 0x00000002 # Create an OpenGL rendering context OPENGLBLIT 0x0000000A # OBSOLETE. Create an OpenGL rendering context and use it for blitting. RESIZABLE 0x00000010 # This video mode may be resized NOFRAME 0x00000020 # No window caption or edge frame Used internally (read-only) HWACCEL 0x00000100 # Blit uses hardware acceleration SRCCOLORKEY 0x00001000 # Blit uses a source color key RLEACCELOK 0x00002000 # Private flag RLEACCEL 0x00004000 # Surface is RLE encoded SRCALPHA 0x00010000 # Blit uses source alpha blending PREALLOC 0x01000000 # Surface uses preallocated memory
pygame.ref.surface#pygame.Surface.get_flags
get_height() get the height of the Surface get_height() -> height Return the height of the Surface in pixels.
pygame.ref.surface#pygame.Surface.get_height
get_locked() test if the Surface is current locked get_locked() -> bool Returns True when the Surface is locked. It doesn't matter how many times the Surface is locked.
pygame.ref.surface#pygame.Surface.get_locked
get_locks() Gets the locks for the Surface get_locks() -> tuple Returns the currently existing locks for the Surface.
pygame.ref.surface#pygame.Surface.get_locks
get_losses() the significant bits used to convert between a color and a mapped integer get_losses() -> (R, G, B, A) Return the least significant number of bits stripped from each color in a mapped integer. This value is not needed for normal pygame usage.
pygame.ref.surface#pygame.Surface.get_losses
get_masks() the bitmasks needed to convert between a color and a mapped integer get_masks() -> (R, G, B, A) Returns the bitmasks used to isolate each color in a mapped integer. This value is not needed for normal pygame usage.
pygame.ref.surface#pygame.Surface.get_masks
get_offset() find the position of a child subsurface inside a parent get_offset() -> (x, y) Get the offset position of a child subsurface inside of a parent. If the Surface is not a subsurface this will return (0, 0).
pygame.ref.surface#pygame.Surface.get_offset
get_palette() get the color index palette for an 8-bit Surface get_palette() -> [RGB, RGB, RGB, ...] Return a list of up to 256 color elements that represent the indexed colors used in an 8-bit Surface. The returned list is a copy of the palette, and changes will have no effect on the Surface. Returning a list of Color(with length 3) instances instead of tuples. New in pygame 1.9.
pygame.ref.surface#pygame.Surface.get_palette
get_palette_at() get the color for a single entry in a palette get_palette_at(index) -> RGB Returns the red, green, and blue color values for a single index in a Surface palette. The index should be a value from 0 to 255. New in pygame 1.9: Returning Color(with length 3) instance instead of a tuple.
pygame.ref.surface#pygame.Surface.get_palette_at
get_parent() find the parent of a subsurface get_parent() -> Surface Returns the parent Surface of a subsurface. If this is not a subsurface then None will be returned.
pygame.ref.surface#pygame.Surface.get_parent
get_pitch() get the number of bytes used per Surface row get_pitch() -> int Return the number of bytes separating each row in the Surface. Surfaces in video memory are not always linearly packed. Subsurfaces will also have a larger pitch than their real width. This value is not needed for normal pygame usage.
pygame.ref.surface#pygame.Surface.get_pitch
get_rect() get the rectangular area of the Surface get_rect(**kwargs) -> Rect Returns a new rectangle covering the entire surface. This rectangle will always start at (0, 0) with a width and height the same size as the image. You can pass keyword argument values to this function. These named values will be applied to the attributes of the Rect before it is returned. An example would be mysurf.get_rect(center=(100, 100)) to create a rectangle for the Surface centered at a given position.
pygame.ref.surface#pygame.Surface.get_rect
get_shifts() the bit shifts needed to convert between a color and a mapped integer get_shifts() -> (R, G, B, A) Returns the pixel shifts need to convert between each color and a mapped integer. This value is not needed for normal pygame usage.
pygame.ref.surface#pygame.Surface.get_shifts