cocos2dx3.2 创建界面菜单的简单使用

前端之家收集整理的这篇文章主要介绍了cocos2dx3.2 创建界面菜单的简单使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


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

猜你在找的Cocos2d-x相关文章