Sprite Scenes#

arcade.Scene#

class arcade.Scene[source]#

Class that represents a scene object. Most games will use Scenes to render their Sprites. For examples on how to use this class, see: https://api.arcade.academy/en/latest/tutorials/views/index.html

Attributes:
sprite_lists:

A list of SpriteList objects. The order of this list is the order in which they will be drawn.

name_mapping:

A dictionary of SpriteList objects. This contains the same lists as the sprite_lists attribute, but is a mapping of them by name. This is not necessarily in the same order as the sprite_lists attribute.

add_sprite(name: str, sprite: Sprite) None[source]#

Add a Sprite to a SpriteList in the Scene with the specified name.

If the desired SpriteList does not exist, it will automatically be created and added to the Scene. This will default the SpriteList to be added to the end of the draw order, and created with no extra options like using spatial hashing.

If you need more control over where the SpriteList goes or need it to use Spatial Hash, then the SpriteList should be added separately and then have the Sprites added.

Parameters:
  • name (str) – The name of the SpriteList to add to or create.

  • sprite (Sprite) – The Sprite to add.

add_sprite_list(name: str, use_spatial_hash: bool = False, sprite_list: Optional[SpriteList] = None) None[source]#

Add a SpriteList to the scene with the specified name.

This will add a new SpriteList to the scene at the end of the draw order.

If no SpriteList is supplied via the sprite_list parameter then a new one will be created, and the use_spatial_hash parameter will be respected for that creation.

Parameters:
  • name (str) – The name to give the SpriteList.

  • use_spatial_hash (bool) – Wether or not to use spatial hash if creating a new SpriteList.

  • sprite_list (SpriteList) – The SpriteList to add, optional.

add_sprite_list_after(name: str, after: str, use_spatial_hash: bool = False, sprite_list: Optional[SpriteList] = None) None[source]#

Add a SpriteList to the scene with the specified name after a specific SpriteList.

This will add a new SpriteList to the scene after the specified SpriteList in the draw order.

If no SpriteList is supplied via the sprite_list parameter then a new one will be created, and the use_spatial_hash parameter will be respected for that creation.

Parameters:
  • name (str) – The name to give the SpriteList.

  • after (str) – The name of the SpriteList to place this one after.

  • use_spatial_hash (bool) – Wether or not to use spatial hash if creating a new SpriteList.

  • sprite_list (SpriteList) – The SpriteList to add, optional.

add_sprite_list_before(name: str, before: str, use_spatial_hash: bool = False, sprite_list: Optional[SpriteList] = None) None[source]#

Add a SpriteList to the scene with the specified name before a specific SpriteList.

This will add a new SpriteList to the scene before the specified SpriteList in the draw order.

If no SpriteList is supplied via the sprite_list parameter then a new one will be created, and the use_spatial_hash parameter will be respected for that creation.

Parameters:
  • name (str) – The name to give the SpriteList.

  • before (str) – The name of the SpriteList to place this one before.

  • use_spatial_hash (bool) – Wether or not to use spatial hash if creating a new SpriteList.

  • sprite_list (SpriteList) – The SpriteList to add, optional.

draw(names: Optional[List[str]] = None, **kwargs) None[source]#

Draw the Scene.

If names parameter is provided then only the specified SpriteLists will be drawn. They will be drawn in the order that the names in the list were arranged. If names is not provided, then every SpriteList in the scene will be drawn according the order of the main sprite_lists attribute of the Scene.

Parameters:
  • names (Optional[List[str]]) – A list of names of SpriteLists to draw.

  • 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], Tuple[int, int, int, int]] = (0, 0, 0, 255), line_thickness: float = 1, names: Optional[List[str]] = None) None[source]#

Draw hitboxes for all sprites in the scene.

If names parameter is provided then only the specified SpriteLists will be drawn. They will be drawn in the order that the names in the list were arranged. If names is not provided, then every SpriteList in the scene will be drawn according to the order of the main sprite_lists attribute of the Scene.

classmethod from_tilemap(tilemap: TileMap) Scene[source]#

Create a new Scene from a TileMap object.

This will look at all the SpriteLists in a TileMap object and create a Scene with them. This will automatically keep SpriteLists in the same order as they are defined in the TileMap class, which is the order that they are defined within Tiled.

Parameters:

tilemap (TileMap) – The TileMap object to create the scene from.

get_sprite_list(name: str) SpriteList[source]#

Helper function to retrieve a SpriteList by name.

The name mapping can be accessed directly, this is just here for ease of use.

Parameters:

name (str) – The name of the SpriteList to retrieve.

move_sprite_list_after(name: str, after: str) None[source]#

Move a given SpriteList in the scene to after another given SpriteList.

This will adjust the render order so that the SpriteList specified by name is placed after the one specified by after.

Parameters:
  • name (str) – The name of the SpriteList to move.

  • after (str) – The name of the SpriteList to place it after.

move_sprite_list_before(name: str, before: str) None[source]#

Move a given SpriteList in the scene to before another given SpriteList.

This will adjust the render order so that the SpriteList specified by name is placed before the one specified by before.

Parameters:
  • name (str) – The name of the SpriteList to move.

  • before (str) – The name of the SpriteList to place it before.

on_update(delta_time: float = 0.016666666666666666, names: Optional[List[str]] = None) None[source]#

Used to call on_update of SpriteLists contained in the scene. Similar to update() but allows passing a delta_time variable.

If names parameter is provided then only the specified spritelists will be updated. If names is not provided, then every SpriteList in the scene will have on_update called.

Parameters:
  • delta_time (float) – Time since last update.

  • names (Optional[List[str]]) – A list of names of SpriteLists to update.

remove_sprite_list_by_name(name: str) None[source]#

Remove a SpriteList by it’s name.

This function serves to completely remove the SpriteList from the Scene.

Parameters:

name (str) – The name of the SpriteList to remove.

update(names: Optional[List[str]] = None) None[source]#

Used to update SpriteLists contained in the scene.

If names parameter is provided then only the specified spritelists will be updated. If names is not provided, then every SpriteList in the scene will be updated.

Parameters:

names (Optional[List[str]]) – A list of names of SpriteLists to update.

update_animation(delta_time: float, names: Optional[List[str]] = None) None[source]#

Used to update the animation of SpriteLists contained in the scene.

If names parameter is provided then only the specified spritelists will be updated. If names is not provided, then every SpriteList in the scene will be updated.

Parameters:
  • delta_time (float) – The delta time for the update.

  • names (Optional[List[str]]) – A list of names of SpriteLists to update.