Write your own cocos2dx game engine (2) - applicationDidFinishLaunching
5337 단어 cocos2d-xGame Engine
In the run method, the applicationDidFinishLaunching method is called. Where is this method?
It can be seen that this method is not implemented in Application. This method comes from Application's base class ApplicationProtocol.
In ApplicationProtocol, applicationDidFinishLaunching is declared as a pure virtual function, and the final implementation is placed in AppDelegate.
Modify the code in the previous section.
//AppDelegate.h
#ifndef __APP_DELEGATE__
#define __APP_DELEGATE__
#include "Application.h"
#include <iostream>
class AppDelegate: private Application {
public:
virtual bool applicationDidFinishLaunching() {
std::cout << "delegate applicationDidFinishLaunching" << std::endl;
return true;
}
};
#endif
Added an implementation of the pure virtual function applicationDidFinishLaunching in which a sentence is printed.//Application.h
#ifndef __APPLICATION__
#define __APPLICATION__
#include "ApplicationProtocol.h"
#include <iostream>
class Application: public ApplicationProtocol {
public:
Application() {
sm_pSharedApplication = this;
}
static Application* getInstance() {
return sm_pSharedApplication;
}
int run() {
std::cout << "App run ..." << std::endl;
if (!applicationDidFinishLaunching()) {
return 1;
}
}
protected:
static Application * sm_pSharedApplication;
};
Application * Application::sm_pSharedApplication = 0;
#endif
Added a call to applicationDidFinishLaunching in Application and let him inherit from the abstract class ApplicationProtocol.//ApplicationProtocol.h
class ApplicationProtocol {
public:
virtual ~ApplicationProtocol(){}
virtual bool applicationDidFinishLaunching() = 0;
};
Declare the pure virtual function applicationDidFinishLaunching in this abstract class.Compile and run to see the final output:
App run ... delegate applicationDidFinishLaunching
Attached code: demo2
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 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에 따라 라이센스가 부여됩니다.