// creating a menu with a single item // create a menu itemauto closeItem = MenuItemImage::create("Closenormal.png","CloseSelected.png",CC_CALLBACK_1(HelloWorld::menuCloseCallback,this));auto menu = Menu::create(closeItem,NulL);this->addChild(menu,1);
菜单还可以使用MenuItem对象的Vector创建:
11 12
// creating a Menu from a Vector of items Vector<MenuItem*> MenuItems;auto closeItem = MenuItemImage::create("Closenormal.png",CC_CALLBACK_1(HelloWorld::menuCloseCallback,153)!important; background:none!important">this));MenuItems.pushBack(closeItem);/* repeat for as many menu items as needed */auto menu = Menu::createWithArray(MenuItems);lambda函数是指可以在源代码中编写内联函数的函数。Cocos2d-x中可以使用lambda函数,你甚至可以将lambda函数作为回调函数。除了Menu回调,lambda函数可用作多种函数。
一个简单的lambda函数:
auto func = [] () { cout << "Hello world"; };func(); // Now call the function
使用lambda作为Action函数:
3
auto action1 = CallFunc::create([&](){std::cout << "using a Lambda callback" << std::endl;});
auto checkBox = CheckBox::create("check_Box_normal.png","check_Box_normal_press.png","check_Box_active.png","check_Box_normal_disable.png","check_Box_active_disable.png");checkBox->setposition(Vec2(0,0));checkBox->addEventListener(CC_CALLBACK_2(UICheckBoxTest::selectedEvent,153)!important; background:none!important">this));this->addChild(checkBox);
auto loadingbar = Loadingbar::create("slIDerProgress.png");loadingbar->setDirection(Loadingbar::Direction::RIGHT);loadingbar->setposition(Vec2(0,0));this->addChild(loadingbar);
SlIDer(滑动条)
滑动条允许用户通过移动一个指标来设定值。创建一个SlIDer:
7
auto slIDer = SlIDer::create();slIDer->loadbarTexture("slIDerTrack.png");slIDer->loadSlIDBallTextures("slIDerThumb.png","slIDerThumb.png","");slIDer->loadProgressbarTexture("slIDerProgress.png");slIDer->setposition(Vec2(0,0));slIDer->addEventListener(CC_CALLBACK_2(UiSliderTest::slIDerEvent,153)!important; background:none!important">this));this->addChild(slIDer);
auto imageVIEw = ImageVIEw::create("ccicon.png");imageVIEw->setposition(Vec2(0,0));this->addChild(imageVIEw);
还可以通过SpriteFrame创建一个ImageVIEw:
auto imageVIEw = ImageVIEw::create("ccicon.png",TextureResType::PList);imageVIEw->setposition(Vec2(0,153)!important; background:none!important">this->addChild(imageVIEw);
auto textBMFont = TextBMFont::create("BMFont","bitmapFontTest2.fnt");textBMFont->setposition(Vec2(0,153)!important; background:none!important">this->addChild(textBMFont);
auto textAtlas = TextAtlas::create("1234567890","labelatlas.png",17,22,"0");textAtlas->setposition(Vec2(0,153)!important; background:none!important">this->addChild(textAtlas);
auto textFIEld = TextFIEld::create("input words here",30);textFIEld->setposition(Vec2(0,0));textFIEld->addEventListener(CC_CALLBACK_2(UITextFIEldTest::textFIEldEvent,153)!important; background:none!important">this));this->addChild(textFIEld);
评论列表(0条)