Sprite - JakeTurner616/pygame-lua-bindings GitHub Wiki
Pygame sprite functions
SpriteWrapper
A wrapper class for pygame.sprite.Sprite
.
Methods:
__init__()
Initialize the SpriteWrapper.
update(*args)
Update the sprite.
add(*groups)
Add the sprite to one or more groups.
remove(*groups)
Remove the sprite from one or more groups.
kill()
Kill the sprite, removing it from all groups.
alive()
Check if the sprite is alive (still in any group).
Returns:
True
if the sprite is alive, otherwise False
.
groups()
Get a list of all groups that the sprite belongs to.
Returns: A list of groups.
set_image(width, height, color)
Set the image of the sprite with the specified width, height, and color.
Parameters:
width
: The width of the image.height
: The height of the image.color
: The color of the image, either as a tuple or a Lua table.
Returns: None
get_rect()
Get the rectangle of the sprite.
Returns:
A dictionary with keys x
, y
, width
, and height
.
set_rect(x, y, width=None, height=None)
Set the rectangle of the sprite.
Parameters:
x
: The x-coordinate of the rectangle.y
: The y-coordinate of the rectangle.width
: The width of the rectangle. Default is 0 if not provided.height
: The height of the rectangle. Default is 0 if not provided.
Returns: None
from_sprite(sprite)
Create a SpriteWrapper from an existing sprite.
Parameters:
sprite
: An existingpygame.sprite.Sprite
object.
Returns:
A SpriteWrapper
object.
GroupWrapper
A wrapper class for pygame.sprite.Group
.
Methods:
__init__()
Initialize the GroupWrapper.
sprites()
Get a list of all sprites in the group.
Returns:
A list of SpriteWrapper
objects.
add(*sprites)
Add one or more sprites to the group.
Parameters:
sprites
: One or moreSpriteWrapper
objects.
Returns: None
remove(*sprites)
Remove one or more sprites from the group.
Parameters:
sprites
: One or moreSpriteWrapper
objects.
Returns: None
has(*sprites)
Check if the group contains one or more sprites.
Parameters:
sprites
: One or moreSpriteWrapper
objects.
Returns:
True
if the group contains all specified sprites, otherwise False
.
update(*args)
Update all sprites in the group.
Returns: None
draw(surface)
Draw all sprites in the group onto the specified surface.
Parameters:
surface
: Apygame.Surface
object.
Returns: None
clear(surface, background)
Clear the group from the surface, restoring the background.
Parameters:
surface
: Apygame.Surface
object.background
: Apygame.Surface
or a callable for clearing the background.
Returns: None
empty()
Empty the group, removing all sprites.
Returns: None
from_group(group)
Create a GroupWrapper from an existing group.
Parameters:
group
: An existingpygame.sprite.Group
object.
Returns:
A GroupWrapper
object.
WeakSpriteWrapper
A wrapper class for pygame.sprite.WeakSprite
, inheriting from SpriteWrapper
.
Methods:
__init__()
Initialize the WeakSpriteWrapper.
DirtySpriteWrapper
A wrapper class for pygame.sprite.DirtySprite
, inheriting from SpriteWrapper
.
Methods:
__init__()
Initialize the DirtySpriteWrapper.
set_dirty(value)
Set the dirty flag for the sprite.
Parameters:
value
: The dirty flag value.
Returns: None
LayeredUpdatesWrapper
A wrapper class for pygame.sprite.LayeredUpdates
, inheriting from GroupWrapper
.
Methods:
__init__()
Initialize the LayeredUpdatesWrapper.
change_layer(sprite, new_layer)
Change the layer of a sprite.
Parameters:
sprite
: ASpriteWrapper
object.new_layer
: The new layer value.
Returns: None
get_layer_of_sprite(sprite)
Get the layer of a sprite.
Parameters:
sprite
: ASpriteWrapper
object.
Returns: The layer value.
get_sprites_from_layer(layer)
Get all sprites from a specific layer.
Parameters:
layer
: The layer value.
Returns:
A list of SpriteWrapper
objects.
from_group(group)
Create a LayeredUpdatesWrapper from an existing group.
Parameters:
group
: An existingpygame.sprite.LayeredUpdates
object.
Returns:
A LayeredUpdatesWrapper
object.
Collision Detection Functions
spritecollide(sprite, group, dokill)
Detect collisions between a sprite and a group.
Parameters:
sprite
: ASpriteWrapper
object.group
: AGroupWrapper
object.dokill
: Whether to kill the collided sprites.
Returns:
A list of SpriteWrapper
objects that collided.
collide_rect(left, right)
Check for collision between two sprites based on their rectangles.
Parameters:
left
: ASpriteWrapper
object.right
: ASpriteWrapper
object.
Returns:
True
if the sprites collide, otherwise False
.
collide_circle(left, right)
Check for collision between two sprites based on their circles.
Parameters:
left
: ASpriteWrapper
object.right
: ASpriteWrapper
object.
Returns:
True
if the sprites collide, otherwise False
.