Wumao's cocos2d-x study notes 02-basic project source code analysis
3232 단어 cocos2d-x
The main.cpp entry method has a piece of code: return Application::getInstance()->run(); This code calls the run method of AppDelegate; the run method calls the applicationDidFinishLaunching method of AppDelegate, and the HelloWorld scene class is created in the applicationDidFinishLaunching method auto scene = HelloWorld::createScene();, and run the scene class director->runWithScene(scene);. The createScene method of the HelloWorld scene class calls the static method create method of HelloWorld. Isn't it strange, because this method is not seen in the HelloWorld scene class, in fact, this method is implemented by the macro CREATE_FUNC(HelloWorld);. In the CREATE_FUNC macro definition, the init method of HelloWorld is called, so a scene class must implement at least three methods: createScene, init, and CREATE_FUNC.
Scene* HelloWorld::createScene(){
auto scene = Scene::create();
auto layer = HelloWorld::create();// CREATE_FUNC(MyHelloWorldScene);
scene->addChild(layer);
return scene;
}
CREATE_FUNC(__TYPE__):
/**
* define a create function for a specific type, such as Layer
* @param \__TYPE__ class type to add create(), such as Layer
*/
#define CREATE_FUNC(__TYPE__) \
static __TYPE__* create() \
{ \
__TYPE__ *pRet = new(std::nothrow) __TYPE__(); \
if (pRet && pRet->init()) \
{ \
pRet->autorelease(); \
return pRet; \
} \
else \
{ \
delete pRet; \
pRet = NULL; \
return NULL; \
} \
}
The scene itself is meaningless, when we add various layers, sprites, menus to the scene, the scene becomes meaningful.
Scene inherits from Node. The 3.x version of Scene integrates the functionality of the physics engine. So the scene can be seen as a physical world.
But strangely, HelloWorldScene inherits from Layer, not Scene.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Cocos Studio v3.x ListView에 PanelNode를 동적으로 추가해보기Cococs Studio에서 ListView를 설정한 BaseNode와 파트 부분이 되는 PasrtNode를 작성. ListView에 PasrtNode를 추가해 가고, 빨리 GridView적인 것을 만드는 비망록. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.