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();
}
总结以上是内存溢出为你收集整理的cocos2dx3.2 创建界面菜单的简单使用全部内容,希望文章能够帮你解决cocos2dx3.2 创建界面菜单的简单使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)