HTML and CSS Reference
The cc.Layer is where you define touch event handlers. By implementing a method to handle one of the touch
events ( cc.TouchBegan , cc.TouchMoved , cc.TouchEnded , or cc.TouchCancelled ), a cc.Layer can react to the player's
interaction. These touch events are propagated to all of the layers within a scene, from front to back, until the claimed
layers catch the event and accept it.
While complex applications will require you to define custom cc.Layer subclasses, Cocos2d provides several
predefined layers. Some examples include cc.Menu (a simple menu layer), cc.ColorLayer (a layer that draws a solid
color), and cc.LayerMultiplex (a layer that lets you multiplex its children, activating one while disabling the others).
Layers may contain any cc.Node as a child, including cc.Sprite , cc.Label , and even other cc.Layer objects.
Because layers are a subclass of cc.Node , they can be transformed manually or programatically by using cc.Action .
A Cocos2d cc.Sprite is similar to sprites that you find in other game engines. It is a 2D image that can be moved,
rotated, scaled, animated, or subjected to other transformations. Sprites (implemented using the cc.Sprite class)
can have other sprites as children. When a parent is transformed, all of its children are transformed as well. Because
sprites are a subclass of cc.Node , they can be transformed manually or programatically by using cc.Action .
Cocos2d-html5 uses the same coordinate system as OpenGL, which is also called “the right-handed Cartesian
coordinate system.” It is popular in the gaming industry; however, it is different from traditional top-left coordinate
systems used in web page designs. The Cocos2d coordinate system is illustrated in Figure 24-3 .
Figure 24-3. Cocos2d coordinate system
For a 2D game,
The x-axis starts at the left side of the screen and increases to the right.
The y-axis starts at the bottom of the screen and increases upwards.
The origin (x = 0, y = 0) is at the bottom-left corner of screen. It is the first quadrant of the right-handed Cartesian