标签:fonts 设置 art 音乐 init path eve cacti 标题
游戏主菜单页面
BeginLayer类封装该页面。init函数初始化该页面布景
该页面背景
isDialog = false; setKeypadEnabled(true); //开启按键事件 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); //获取可见区域原点坐标 CCSprite* bSprite = CCSprite::create("pic/background.png");//背景图片 bSprite->setPosition(ccp(origin.x, origin.y)); bSprite->setAnchorPoint(ccp(0, 0));//默认锚点为0.5,0.5 this->addChild(bSprite, 0);
创建菜单项按键
主菜单键及回调
CCMenuItemImage *continueItem = CCMenuItemImage::create ( "menuContinue.png", //平时的图片 "menuContinue2.png", //选中时的图片 this, menu_selector(BeginLayer::continueSence)//点击时运行的回调方法 );
继续键及回调
CCMenuItemImage *continueItem = CCMenuItemImage::create ( "menuContinue.png", //平时的图片 "menuContinue2.png", //选中时的图片 this, menu_selector(BeginLayer::continueSence)//点击时运行的回调方法 );
成就键及回调
CCMenuItemImage *achievementsItem = CCMenuItemImage::create ( "menuAchievements.png", //平时的图片 "menuAchievements2.png", //选中时的图片 this, menu_selector(BeginLayer::achievementsSence)//点击时运行的回调方法 );
关于键及回调
CCMenuItemImage *aboutItem = CCMenuItemImage::create ( "menuAbout.png", //平时的图片 "menuAbout2.png", //选中时的图片 this, menu_selector(BeginLayer::aboutSence)//点击时运行的回调方法 );
设置键及回调
CCMenuItemImage *settItem = CCMenuItemImage::create ( "set.png", //平时的图片 "set2.png", //选中时的图片 this, menu_selector(BeginLayer::setSence)//点击时运行的回调方法 );
创建标题
CCSprite* tSprite = CCSprite::create("pic/title.png"); //设置精灵对象的位置 tSprite->setPosition(ccp(origin.x, origin.y+visibleSize.height-207)); tSprite->setAnchorPoint(ccp(0, 0)); this->addChild(tSprite, 3);
组合成菜单对象
pMenu = CCMenu::create(continueItem,newMenuItem,achievementsItem,aboutItem,settItem,NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, GAME_LEVEL_WYF);
为菜单项出场加入动画
CCNode* child = NULL; CCArray * pArray = pMenu->getChildren();//获取全部菜单项 int count = pArray->count();//个数 for(int m=0;m<count;m++)//遍历菜单项 { child = (CCNode*)(pArray->objectAtIndex(m));//每一个菜单项 child->setPosition(ccp(400,550));//初始位置 CCActionInterval* moveTo1 = CCMoveTo::create(0.2f,ccp(400,-40)); CCActionInterval* moveTo2 = CCMoveTo::create(0.25f*(count-m),ccp(400,80+80*(count-1-m))); CCActionInterval* move_ease_in2 = CCEaseElasticOut::create(moveTo2);//moveTo2振幅效果 CCDelayTime *delay = CCDelayTime::create(0.2f*(count-m-1));//每一个菜单项出场间歇时间 CCSequence* seq = CCSequence::create(delay,moveTo1,move_ease_in2, NULL);// child->runAction(seq);//运行 }
主菜单键回调。通过调用toNewGameLayer来切换到NewGameLayer场景,真正的游戏主页面
void BeginLayer::newSence(CCObject* pSender) { tsm->toNewGameLayer(1);//第一关 }
继续键回调,先获取上次的数据。然后切换到对应关卡
void BeginLayer::continueSence(CCObject* pSender) { //int gK=JNIUtil::getInt("continue",1,classPath.c_str()); tsm->toNewGameLayer(1); }
成就键回调,调用toAchieveLayer切换到AchieveLayer场景。来统计游戏数据中玩家最高分、最高关卡
void BeginLayer::achievementsSence(CCObject* pSender) { tsm->toAchieveLayer(); }
关于键回调。调用toHelpLayer切换到HelpLayer场景,提示游戏帮助手冊
void BeginLayer::aboutSence(CCObject* pSender) { tsm->toHelpLayer(); }
设置键回调,调用toSetLayer切换到SetLayer场景,设置游戏音乐及音效
void BeginLayer::setSence(CCObject* pSender) { tsm->toSetLayer(); }
返回键处理,调用toOutLayer切换到推出游戏场景
void BeginLayer::keyBackClicked() { if(isDialog) { return; } isDialog = true; //暂停声音播放 CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); tsm->toOutLayer(); }
标签:fonts 设置 art 音乐 init path eve cacti 标题
原文地址:http://www.cnblogs.com/jhcelue/p/7222321.html