Cocos2d-x -- 图片菜单按钮
Scene* MainMenu::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = MainMenu::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool MainMenu::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); auto menuTitle = MenuItemImage::create("MainMenuScreen/Game_Title.png", "MainMenuScreen/Game_Title.png"); auto playItem = MenuItemImage::create("MainMenuScreen/Play_Button.png", "MainMenuScreen/Play_Button(Click).png", CC_CALLBACK_1(MainMenu::GoToGameScene, this)); auto menu = Menu::create(menuTitle, playItem, NULL); menu->alignItemsVerticallyWithPadding(visibleSize.height / 4); this->addChild(menu); return true; } void MainMenu::GoToGameScene(cocos2d::Ref *pSender) { auto scene = GameScreen::createScene(); Director::getInstance()->replaceScene(scene); }
技术改变世界