bool StartLayer::init()
{
if (!Layer::init())
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
auto orign = Director::getInstance()->getVisibleOrigin();
auto bg = Sprite::create("LittleGirl.jpg");
bg->setPosition(Vec2(orign + visibleSize / 2));
this->addChild(bg);
auto item1 = MenuItemImage::create();
auto nsf = SpriteFrame::create("StartButton.jpg",Rect(0, 0,200,58));
item1->setNormalSpriteFrame(nsf);
item1->setCallback(CC_CALLBACK_1(StartLayer::StartGame,this));
item1->setPositionX(-100.0f);
auto item2 = MenuItemImage::create();
item2->setPosition(Vec2(- 100.0f,item1->getPositionY() - 70));
auto ssf = SpriteFrame::create("ExitButton.jpg",58));
item2->setNormalSpriteFrame(ssf);
item2->setCallback(CC_CALLBACK_1(StartLayer::ExitGame,this));
auto menu = Menu::create(item1,item2,NULL);
auto size = menu->getContentSize();
menu->setPosition(Vec2(orign + visibleSize / 2));
addChild(menu);
return true;
}
void StartLayer::StartGame(cocos2d::Ref *ref)
{
CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
auto tollScene = TollgateScene::create();
Director::getInstance()->replaceScene(tollScene);
}
void StartLayer::ExitGame(cocos2d::Ref *ref)
{
Director::getInstance()->end();
}
原文链接:/cocos2dx/345358.html