Cocos2d 之FlyBird开发---GameAbout类

|   版权声明:本文为博主原创文章,未经博主允许不得转载。(笔者才疏学浅,如有错误,请多多指教)

 

  一般像游戏关于的这种界面中,主要显示的是游戏的玩法等。

 

GameAbout.h

#ifndef _GAME_ABOUT_H_
#define _GAME_ABOUT_H_
 
//////////////////////////////////////////////////////////
////////   此文件主要描述关于界面
 
#include "cocos2d.h"
USING_NS_CC;
 
class GameAbout : public cocos2d::Layer
{
private:
     cocos2d::MenuItemImage* awayItem;
     cocos2d::Sprite* background;
public:
     static cocos2d::Scene* createScene();
     virtual bool init();
     void aboutInterface();
     void goMainInterface(cocos2d::Ref*);
     CREATE_FUNC(GameAbout);
};
#endif // _GAME_ABOUT_H_

 

GameAbout.cpp

#include "GameAbout.h"
#include "GameUnit.h"
#include "MainMenu.h"
 
unit u1;
 
cocos2d::Scene* GameAbout::createScene()
{
     auto scene = Scene::create();
     auto layer = GameAbout::create();
     scene->addChild(layer);
     return scene;
}
 
bool GameAbout::init()
{
     if (!Layer::init())
     {
              return false;
     }
 
 
     this->aboutInterface();
 
     
     //best->setColor(Color3B(0, 0, 0));
     //best->setString(__String::createWithFormat("%d", Score - 1)->getCString());
 
     return true;
}
 
void GameAbout::aboutInterface()
{
     background = Sprite::create("background/about.png");
     background->setPosition(Vec2(u1.winOrigin().x + u1.winSize().width / 2,
              u1.winOrigin().y + u1.winSize().height / 2));
     background->setScale(u1.scaleX(background, u1.winSize()),
              u1.scaleY(background, u1.winSize()));
     this->addChild(background, 0);
 
     awayItem = MenuItemImage::create(
              "button/away.png",
              "button/buttom.png",
              CC_CALLBACK_1(GameAbout::goMainInterface, this));
     awayItem->setPosition(Vec2(u1.winOrigin().x + awayItem->getContentSize().width / 2,
              u1.winOrigin().y + awayItem->getContentSize().height / 2));
     auto m = Menu::create(awayItem, NULL);
     m->setPosition(Vec2::ZERO);
     this->addChild(m, 2);    
}
 
void GameAbout::goMainInterface(cocos2d::Ref* pSender)
{
     Director::getInstance()->replaceScene(TransitionFadeBL::create(1,
              MainMenu::createScene()));
}

  

函数的功能介绍详见:http://lipei95.blog.163.com/blog/static/257578646201671924726318/

 

效果图:

posted @ 2016-08-23 17:01  Geore  阅读(222)  评论(0编辑  收藏  举报