Game Object Model

The Game Object Model.

class ppb.gomlib.Children[source]

A container for game objects.

Supports tagging.

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

Add a child.

Parameters:
  • child – Any Hashable object. The item to be added.
  • tags – An iterable of Hashable objects. 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[CT_co] = None, tag: Hashable = None, **_) → Iterator[T_co][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. 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: Hashable) → Hashable[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: Hashable, tags: Iterable[T_co] = ()) → None[source]

Shorthand for Children.add()

children = None

The children of this object

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

Shorthand for Children.get()

kinds

Shorthand for Children.kinds()

Deprecated since version 0.10: Use .children.kinds() instead.

remove(child: Hashable) → None[source]

Shorthand for Children.remove()

tags

Shorthand for Children.tags()

Deprecated since version 0.10: Use .children.tags() instead.

ppb.gomlib.walk(root)[source]

Conducts a walk of the GOM tree from the root.

Includes the root.

Is non-recursive.