Layers

A Layer has as size the whole drawable area (window or screen), and knows how to draw itself. It can be semi transparent (having holes and/or partial transparency in some/all places), allowing to see other layers behind it. 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.

layers.png

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 classes, cocos2d provides a library of useful predefined layers (a simple menu layer: Menu, a color layer: ColorLayer, a multiplexor between other layers: MultiplexLayer, a map layer: HexMapLayer, and more ).

Layers can have Sprite, Label, HTMLLabel and even other Layer objects as children.

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.