Cocos2d-x testBasic文件阅读
testBasic.h
class TestScene: public CCScene { public: TestScene(bool bPortrait = false); virtual void onEnter(); //子类重载这个方法,运行自己的场景 virtual void runThisTest() = 0; //返回到主菜单场景 virtual void MainMenuCallback(CCObject* pSender); } typedef CCLayer* (*NEWTESTFUNC)(); #define TESTLAYER_CREATE_FUNC(className) \ static CCLayer* create##className() \ { return new className();} #define CF(className) create##className
testBasic.cpp
TestScene::TestScene(bool bPortrait) { CCScene::init(); } void TestScene::onEnter() { //调用基类onEnter()方法 CCScene::onEnter(); //创建一个label,内容为"MainMenu",字体为"Arial",大小20 CCLabelTTF *label = CCLabelTTF::create("MainMenu","Arial",20); //创建一个菜单项,用于放置label,并响应菜单项选择回调 CCMenuItemLabel *pMenuItem = CCMenuItemLabel::create(label,this,menu_selector(TestScene::MainMenuCallback)); //创建一个菜单 CCMenu *pMenu = CCMenu::create(pMenuItem,NULL); //设置菜单位置 pMenu->setPosition(CCPointZero); //设置菜单项的位置,位于右下角 pMenuItem-setPosition(ccp(VisibleRect::right().x - 50,VisibleRect::bottom().y + 25)); //添加菜单 addChild(pMenu,1); } void TestScene::MainMenuCallback(CCObject *pSender) { //建立一个场景 CCScene *pScene = CCScene::create(); //建立一个控制层 CCLayer *pLayer = new TestController(); //将层交给Cocos2d-x的内存管理 pLayer->autorelease(); //将层添加到场景 pScene->addChild(pLayer); //显示场景 CCDirector::sharedDirector()->replaceScene(pScene); }