一个新的工程 HelloWorld,
AppDelegate.cpp
applicationDidFinishLanching
初始化一个导演类的对象
auto director = Director::getInstance();
获取GL视图
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
director->setOpenGLView(glview);
}
// turn on display FPS
设置每帧显示
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
设置帧率
director->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object
//创建新的scene
auto scene = HelloWorld::createScene();
// run
director->runWithScene(scene);
AppDelegate.h
HelloWorld.cpp
HelloWorld.h
继承自 cocosd::Layer ,头文件中含有的基本元素:
一个虚函数 virtual bool init(); 用于初始化。可以添加各种UI, button sprite, Label, Layer, menu 等等。
Scene *createScene(), 用于创建新的场景,并返回新场景的指针。
Director 导演类,用于场景的切换