Cocos2dx-v4.0学习-HelloCpp
程序员文章站
2024-03-25 19:25:34
...
1. 你好HelloCpp
打开工程cocos工程后,我们打开
2. 程序入口main.cpp
主要是创建了AppDelegate对象实例,使用其run方法
main () {
AppDelegate app;
return Application::getInstance()->run();
}
3. 初识AppDelegate
class AppDelegate : private cocos2d::Application
{
public:
AppDelegate();
virtual ~AppDelegate();
virtual void initGLContextAttrs();
/**
@brief Implement Director and Scene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching();
/**
@brief Called when the application moves to the background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground();
/**
@brief Called when the application reenters the foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground();
};
- initGLContextAttrs: 设置OpenGL上下文属性
- applicationDidFinishLaunching:实现导演类与初始化场景
- FPS设置(Frames Per Second)
- 设计分辨率
- 创建场景HelloWorld
- applicationDidEnterBackground:程序进入后台的时候调用
- applicationWillEnterForeground:程序进入前台的时候调用
4. 场景HelloWorldScene
HelloWorld继承了Scene, 初始化时创建里文字、精灵,点击关闭事件等