class Actors:
- """ A list of actors. """
+ """ A list of actors.
+
+ Actors may be rendered in different layers. Layers with lower levels
+ are rendered lower than layers with higher ones.
+ """
def __init__(self):
- self._actors = []
+ self._layer_order = []
+ self._layers = {}
+ self.add_layer("default", 0)
+
+ def add_layer(self, name, level):
+ self._layer_order.append((level, name))
+ self._layer_order.sort()
+ self._layers[name] = []
- def add(self, actor):
- self._actors.append(actor)
+ def add(self, actor, layer="default"):
+ self._layers[layer].append(actor)
return actor
- def remove(self, actor):
- self._actors.remove(actor)
+ def remove(self, actor, layer="default"):
+ self._layers[layer].remove(actor)
return actor
def draw(self, screen):
- for actor in self._actors:
- actor.draw() # TODO: allow an option screen to be passed in
+ for lvl, layer in self._layer_order:
+ for actor in self._layers[layer]:
+ actor.draw() # TODO: allow an option screen to be passed in
class Scene: