cocos.layer.base_layers module

Layer class and subclasses.

Layers are typically thought as event handlers and / or as containers that help to organize the scene visuals or logic.

The transform_anchor is set by default to the window’s center, which most of the time provides the desired behavior on rotation and scale.

By default a layer will not listen to events, his is_event_handler must be set to True before the layer enters the stage to enable the automatic registering as event handler.

class Layer

Bases: cocos.cocosnode.CocosNode

A CocosNode that can automatically register to listen to director.window events

on_enter()

Called every time just before the node enters the stage.

on_exit()

Called every time just before the node exits the stage.

is_event_handler = False

If True, the event handlers of this layer will be registered. Defaults to False.

class MultiplexLayer(*layers)

Bases: cocos.layer.base_layers.Layer

A Composite layer that only enables one layer at a time.

This is useful, for example, when you have 3 or 4 menus, but you want to show one at the time.

After instantiation the enabled layer is layers[0]

Parameters:*layers – iterable with the layers to be managed.
switch_to(layer_number)

Switches to another of the layers managed by this instance.

Parameters:layer_number (int) – Must be a number between 0 and the (number of layers - 1). The running layer will receive an on_exit() call, and the new layer will receive an on_enter() call.
Raises:Exception – layer_number was out of bound.