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 rectangles 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...