Hi,
First of all, many thanks to the maintainers of cocos2d-x for this magnificent multi-platform port of objective-c cocos2d.
I’m no expert nor a noob in C++, but not that experienced and have been porting a android game to cocos2d-x, and so far so good
However I’ve some difficulties understanding/dissecting the hello world example, which I assume is where practically everyone starts with.
For example:
-
For simplicity, I would expect that HelloWorldScene would inherit from CCScene, but instead it inherits CCLayer.
Where the CCScene instance is actually achieved from a static member from that class.
Q) What’s the advantage of this, only to have a scene available as static method pointer value ? -
What’s the need/usage of the do/loop in HelloWorldScene::scene() and HelloWorldScene::init() methods ?
-
Regarding the static method which returns a pointer to the new scene instance.
Tried to create a BaseScene with the moving the scene() method which would be inherited from HelloWorldScene, and so on.
But like this way, only get black screen when running the scene which inherited it. (I guess this is a pure C++ noob question)
CCScene* BaseScene::scene()
{
CCScene * scene = NULL;
do
{
// Create scene
scene = CCScene::create();
CC_BREAK_IF(! scene);
// Create layer
BaseScene*layer = BaseScene::create();
CC_BREAK_IF(! layer);
// Add layer to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}