HTML and CSS Reference
In-Depth Information
Extending the Power of Cocos2d-html5 with Cocos2d JavaScript Binding
You can now use Cocos2d-html5 to write games running on HTML5-compatible browsers. With the power of
the Cocos2d JSB, you can use the same code base to run on a PC, mobile device, or even embedded systems.
If you want to know more about JavaScript Binding and the corresponding generators, check out this link: .
Understanding Cocos2d
In the Cocos2d world, everything is a node, and the world is mainly constructed from three types of nodes:
A scene node
Some layer nodes
Lots of sprite nodes
Only one scene can be running at a time, which includes one or more layers, and layers that contain sprite nodes
that are actually displaying something, such as an image, a character, an explosion, and so forth.
Basic Concepts of Cocos2d
Before creating the first scene of your game, you should be familiar with the basic concepts of Cocos2d. If you are
already familiar with these concepts, you can skip to next section.
Now, let's go over a few things about the framework and its basic concepts.
The cc.Director is a shared (singleton) object that takes care of navigating between scenes. It is an important
component for controlling the flow of the game. It knows which scene is currently active and allows you to change
scenes by replacing the current scene or pushing a new one onto the scene stack. When you push a new scene onto
the stack, cc.Director pauses the previous scene but keeps it in memory. Later, when you pop the top scene from
the stack, the paused scene resumes from its last state. cc.Director is also responsible for initializing the scheduler,
action manager, and touch dispatcher.
A scene (implemented with the cc.Scene object) is more or less an independent piece of the app workflow. (Some people
call them “screens” or “stages.”) Your app can have many scenes, but only one of them can be active at a given time.
For example, you could have a game with the following scenes: Intro, Menu, Level 1, Level 2, Winning Scene,
Losing Scene, and High Scores. You can think of each one of these scenes as a separate application that can be
connected to other scenes with a small amount of “glue” code. For example, the Intro scene might go to the Menu
scene when it finishes, and the scene for Level 1 might lead to the scene for Level 2 (if the player wins) or to the Losing
scene (if the player loses). An example of how scenes might flow in a game is shown in Figure 24-1 .
Search WWH ::

Custom Search