Game Development Reference
In-Depth Information
Cocos2d-x - an introduction
So what is a 2D framework? If I had to define it in as few words as possible, I'd say rect-
angles in a loop.
At the heart of Cocos2d-x, you find the Sprite class and what that class does, in simple
terms, is keep a reference to two very important rectangles. One is the image (or texture)
rectangle, also called the source rectangle, and the other is the destination rectangle. If you
want an image to appear in the center of the screen, you will use Sprite . You will pass it
the information of what and where that image source is and where on the screen you want
it to appear.
There is not much that needs to be done to the first rectangle, the source one; but there is a
lot that can be changed in the destination rectangle, including its position on the screen, its
size, opacity, rotation, and so on.
Cocos2d-x will then take care of all the OpenGL drawing necessary to display your image
where you want it and how you want it, and it will do so inside a render loop. Your code
will most likely tap into that same loop to update its own logic.
Pretty much any 2D game you can think of can be built with Cocos2d-x with a few sprites
and a loop.
Note
In Version 3.x of the framework, there was a mild separation between Cocos2d-x and its
counterpart Cocos2d. It dropped the prefix CC in favor of namespaces, embraced C++11
features, and became that much nicer to work with because of it.
Search WWH ::




Custom Search