先来点简单的,说说帮助类。
帮助类非常简单,只是显示一个背景,一个”帮助信息”的Label和一个返回菜单而已。
HelpScene.h :
#ifndef __snakegame__HelpScene__
#define __snakegame__HelpScene__
#include "cocos2d.h"
USING_NS_CC;
class Help :public Layer
{
public:
static Scene * createScene();
CREATE_FUNC(Help);
virtual bool init();
void menuCallBack(Ref * object);
};
#endif /* defined(__snakegame__HelpScene__) */
HelpScene.cpp :
#include "HelpScene.h"
#include "MainMenu.h"
Scene * Help::createScene()
{
auto scene = Scene::create();
auto layer = Help::create();
scene->addChild(layer);
return scene;
}
bool Help::init()
{
if (!Layer::init())
{
return false;
}
auto size = Director::getInstance()->getWinSize();
//添加背景
auto spriteBK = Sprite::create("menuback.png");
spriteBK->setPosition(Point(size.width / 2,size.height / 2));
spriteBK->setOpacity(70);//设置透明度
this->addChild(spriteBK);
//帮助信息
auto labelscore = Label::createWithSystemFont("帮助信息","宋体",25);
labelscore->setPosition(Point(size.width - 80,size.height - 50));
this->addChild(labelscore);
//返回按钮
auto menuItemBack = MenuItemFont::create("Back",CC_CALLBACK_1(Help::menuCallBack,this));
auto menu = Menu::create(menuItemBack,NULL);
menu->setPosition(Point::ZERO);
menuItemBack->setPosition(Point(size.width - menuItemBack->getContentSize().width - 100,menuItemBack->getContentSize().height + 10));
this->addChild(menu);
return true;
}
//点击返回按钮返回到主界面
void Help::menuCallBack(Ref * object)
{
auto scene = MainMenu::createScene();
Director::getInstance()->replaceScene(scene);
}