All About Scenes

Scenes are the terrain where sprites act. Each game has multiple scenes and may transition at any time.

class ppb.BaseScene(*, set_up: Callable = None, **kwargs)[source]
background_color = (0, 0, 100)

An RGB triple of the background, eg (0, 127, 255)


An object representing the view of the scene that’s rendered

add(game_object: Hashable, tags: Iterable[T_co] = ()) → None[source]

Add a game_object to the scene.

  • game_object – Any GameObject object. The item to be added.
  • tags – An iterable of Hashable objects. Values that can be used to retrieve a group containing the game_object.



scene.add(MyGameObject(), tags=("red", "blue")

alias of

get(*, kind: Type[CT_co] = None, tag: Hashable = None, **kwargs) → Iterator[T_co][source]

Get an iterator of GameObjects by kind or tag.

  • kind – Any type. Pass to get a subset of contained GameObjects with the given type.
  • tag – Any Hashable object. Pass to get a subset of contained GameObjects with the given tag.

Pass both kind and tag to get objects that are both that type and that tag.




scene.get(type=MyGameObject, tag="red")
remove(game_object: Hashable) → None[source]

Remove the given object from the scene.

Parameters:game_object – A game object.


sprite_layers() → Iterator[T_co][source]

Return an iterator of the contained Sprites in ascending layer order.

Sprites are part of a layer if they have a layer attribute equal to that layer value. Sprites without a layer attribute are considered layer 0.

This function exists primarily to assist the Renderer subsystem, but will be left public for other creative uses.