Sprite Lists

arcade.SpriteList

class arcade.SpriteList(use_spatial_hash=None, spatial_hash_cell_size=128, is_static=False, atlas: TextureAtlas = None, capacity: int = 100)[source]

Keep a list of sprites. Contains many optimizations around batch-drawing sprites and doing collision detection. For optimization reasons, use_spatial_hash and is_static are very important.

append(sprite: arcade.sprite_list.sprite_list._SpriteType)[source]

Add a new sprite to the list.

Parameters

sprite (Sprite) – Sprite to add to the list.

property atlas: TextureAtlas

Get the texture atlas for this sprite list

property center: Tuple[float, float]

Get the mean center coordinates of all sprites in the list.

clear()[source]

Clears the spritelist

disable_spatial_hashing() None[source]

Turn off spatial hashing.

draw(**kwargs)[source]

Draw this list of sprites.

Parameters
  • filter – Optional parameter to set OpenGL filter, such as gl.GL_NEAREST to avoid smoothing.

  • blend_function – Optional parameter to set the OpenGL blend function used for drawing the sprite list, such as ‘arcade.Window.ctx.BLEND_ADDITIVE’ or ‘arcade.Window.ctx.BLEND_DEFAULT’

draw_hit_boxes(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]] = (0, 0, 0, 255), line_thickness: float = 1)[source]

Draw all the hit boxes in this list

enable_spatial_hashing(spatial_hash_cell_size=128)[source]

Turn on spatial hashing.

extend(sprites: Union[list, arcade.sprite_list.sprite_list.SpriteList])[source]

Extends the current list with the given list

Parameters

sprites (list) – list of Sprites to add to the list

index(sprite: arcade.sprite.Sprite) int[source]

Return the index of a sprite in the spritelist

Parameters

sprite (Sprite) – Sprite to find and return the index of

Return type

int

insert(index: int, sprite: arcade.sprite_list.sprite_list._SpriteType)[source]

Inserts a sprite at a given index.

Parameters
  • index (int) – The index at which to insert

  • sprite (Sprite) – The sprite to insert

move(change_x: float, change_y: float) None[source]

Moves all Sprites in the list by the same amount. This can be a very expensive operation depending on the size of the sprite list.

Parameters
  • change_x (float) – Amount to change all x values by

  • change_y (float) – Amount to change all y values by

on_update(delta_time: float = 0.016666666666666666)[source]

Update the sprite. Similar to update, but also takes a delta-time.

property percent_sprites_moved

Property to estimate what percent of the sprites moved. Use internally to guess if spatial hashing should be turned on or off if the user didn’t specify.

pop(index: int = - 1) arcade.sprite.Sprite[source]

Pop off the last sprite, or the given index, from the list

Parameters

index (int) – Index of sprite to remove, defaults to -1 for the last item.

preload_textures(texture_list: List[Texture]) None[source]

Preload a set of textures that will be used for sprites in this sprite list.

Parameters

texture_list (array) – List of textures.

remove(sprite: arcade.sprite_list.sprite_list._SpriteType)[source]

Remove a specific sprite from the list. :param Sprite sprite: Item to remove from the list

rescale(factor: float) None[source]

Rescale all sprites in the list relative to the spritelists center.

reverse()[source]

Reverses the current list in-place

shuffle()[source]

Shuffles the current list in-place

swap(index_1: int, index_2: int)[source]

Swap two sprites by index :param int index_1: Item index to swap :param int index_2: Item index to swap

update() None[source]

Call the update() method on each sprite in the list.

update_angle(sprite: arcade.sprite.Sprite)[source]

Called by the Sprite class to update the angle in this sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_animation(delta_time: float = 0.016666666666666666)[source]

Call the update_animation in every sprite in the sprite list.

update_color(sprite: arcade.sprite.Sprite) None[source]

Called by the Sprite class to update position, angle, size and color of the specified sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_height(sprite: arcade.sprite.Sprite)[source]

Called by the Sprite class to update the size/scale in this sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_location(sprite: arcade.sprite.Sprite)[source]

Called by the Sprite class to update the location in this sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_position(sprite: arcade.sprite.Sprite) None[source]

Called when setting initial position of a sprite when added or inserted into the SpriteList.

update_location should be called to move them once the sprites are in the list.

Parameters

sprite (Sprite) – Sprite to update.

update_size(sprite: arcade.sprite.Sprite) None[source]

Called by the Sprite class to update the size/scale in this sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_texture(sprite) None[source]

Make sure we update the texture for this sprite for the next batch drawing

update_width(sprite: arcade.sprite.Sprite)[source]

Called by the Sprite class to update the size/scale in this sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

property use_spatial_hash: bool

Boolean variable that controls if this sprite list is using a spatial hash. If spatial hashing is turned on, it takes longer to move a sprite, and less time to see if that sprite is colliding with another sprite.

arcade.check_for_collision

arcade.check_for_collision(sprite1: arcade.sprite.Sprite, sprite2: arcade.sprite.Sprite) bool[source]

Check for a collision between two sprites.

Parameters
  • sprite1 – First sprite

  • sprite2 – Second sprite

Returns

True or False depending if the sprites intersect.

Return type

bool

arcade.check_for_collision_with_list

arcade.check_for_collision_with_list(sprite: arcade.sprite.Sprite, sprite_list: arcade.sprite_list.sprite_list.SpriteList) List[arcade.sprite.Sprite][source]

Check for a collision between a sprite, and a list of sprites.

Parameters
  • sprite (Sprite) – Sprite to check

  • sprite_list (SpriteList) – SpriteList to check against

Returns

List of sprites colliding, or an empty list.

Return type

list

arcade.check_for_collision_with_lists

arcade.check_for_collision_with_lists(sprite: arcade.sprite.Sprite, sprite_lists: List[arcade.sprite_list.sprite_list.SpriteList]) List[arcade.sprite.Sprite][source]

Check for a collision between a Sprite, and a list of SpriteLists. :param Sprite sprite: Sprite to check :param List[SpriteList] sprite_list: SpriteLists to check against :returns: List of sprites colliding, or an empty list. :rtype: list

arcade.get_closest_sprite

arcade.get_closest_sprite(sprite: arcade.sprite.Sprite, sprite_list: arcade.sprite_list.sprite_list.SpriteList) Optional[Tuple[arcade.sprite.Sprite, float]][source]

Given a Sprite and SpriteList, returns the closest sprite, and its distance.

Parameters
  • sprite (Sprite) – Target sprite

  • sprite_list (SpriteList) – List to search for closest sprite.

Returns

Closest sprite.

Return type

Sprite

arcade.get_sprites_at_exact_point

arcade.get_sprites_at_exact_point(point: Union[Tuple[float, float], List[float]], sprite_list: arcade.sprite_list.sprite_list.SpriteList) List[arcade.sprite.Sprite][source]

Get a list of sprites whose center_x, center_y match the given point. This does NOT return sprites that overlap the point, the center has to be an exact match.

Parameters
  • point (Point) – Point to check

  • sprite_list (SpriteList) – SpriteList to check against

Returns

List of sprites colliding, or an empty list.

Return type

list

arcade.get_sprites_at_point

arcade.get_sprites_at_point(point: Union[Tuple[float, float], List[float]], sprite_list: arcade.sprite_list.sprite_list.SpriteList) List[arcade.sprite.Sprite][source]

Get a list of sprites at a particular point. This function sees if any sprite overlaps the specified point. If a sprite has a different center_x/center_y but touches the point, this will return that sprite.

Parameters
  • point (Point) – Point to check

  • sprite_list (SpriteList) – SpriteList to check against

Returns

List of sprites colliding, or an empty list.

Return type

list