Layers

Layers helps you organize the scene in the back to front axis, by example

You can think layers as (usually) transparent sheets where the children are drawn, and the scene as the stack of sheets

layers.png

In non MVC design style some code related to nodes interaction tends to float at the layer holding the entities, providing higher functional units. By example, Menu is a Layer subclass that knows how to layout and animate items, read user input and do control flow.

Layers are the ones defining appearance and behavior, so most of your programming time will be spent coding Layer subclasses that do what you need.

The Layer is where you define event handlers. Events are propagated to layers (from front to back) until some layer catches the event and accepts it.

Even if any serious app will require you to define some Layer subclasses, cocos2d provides some useful specialized layers

To make loading of appropriate assets easier you may override the init method of your Layer subclass. This will be called when your Layer is created.

Since layers are subclass of CocosNode, they can be transformed manually or by using actions. See Actions, Transformations and Effects for more detail about actions.