Game Object Model#

The Game Object Model.

class ppb.gomlib.Children[source]#

A container for game objects.

Supports tagging.

add(child: GameObject, tags: Iterable[Hashable] = ()) GameObject[source]#

Add a child.

Parameters:
  • child – Any Game Object. The item to be added.

  • tags – An iterable of Hashable objects. (Probably strings.) Values that can be used to retrieve a group containing the child.

Examples:

children.add(MyObject())

children.add(MyObject(), tags=("red", "blue")
get(*, kind: Type = None, tag: GameObject = None, **_) Iterator[source]#

Iterate over the objects by kind or tag.

Parameters:
  • kind – Any type. Pass to get a subset of contained items with the given type.

  • tag – Any Hashable object. (Probably strings.) Pass to get a subset of contained items with the given tag.

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

Examples:

children.get(type=MyObject)

children.get(tag="red")

children.get(type=MyObject, tag="red")
kinds()[source]#

Generates all types of the children (including super types)

remove(child: GameObject) GameObject[source]#

Remove the given object from the container.

Parameters:

child – A hashable contained by container.

Example:

container.remove(myObject)
tags()[source]#

Generates all of the tags currently in the collections

walk()[source]#

Iterate over the children and their children.

class ppb.gomlib.GameObject(**props)[source]#

A generic parent class for game objects. Handles:

  • Property-based init (Sprite(position=pos, image=img))

  • Children management

add(child: GameObject, tags: Iterable = ()) None[source]#

Shorthand for Children.add()

children: Children#

The children of this object

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

Shorthand for Children.get()

remove(child: GameObject) GameObject[source]#

Shorthand for Children.remove()

ppb.gomlib.walk(root) Iterable[GameObject][source]#

Conducts a walk of the GOM tree from the root.

Includes the root.

Is non-recursive.