在.h文件中添加 void button_touch_test(Object *); 类似的这样的回调函数的声明(自己写的回调函数)
auto giveUpMenuItem = MenuItemImage::create( "button01.png","button02.png",CC_CALLBACK_1(GameScene::button_giveUp,this)); giveUpMenuItem->setPosition(Point(60,40)); auto genZhuMenuItem = MenuItemImage::create( "button01.png",CC_CALLBACK_1(GameScene::button_jiaZhu,this)); genZhuMenuItem->setPosition(Point(190,40)); auto yiLvMenuItem = MenuItemImage::create( "button01.png",CC_CALLBACK_1(GameScene::button_yilv,this)); yiLvMenuItem->setPosition(Point(320,40)); auto starMenu = Menu::create(giveUpMenuItem,genZhuMenuItem,yiLvMenuItem,NULL); starMenu->setPosition(Point::ZERO); this->addChild(starMenu,1); //按钮上添加文字(暂时的功能,后期完善可以删掉) auto button_label01 = Label::createWithSystemFont("giveUp","Arial",17); button_label01->setPosition(Point(60,40)); this->addChild(button_label01,2);回调函数的实现:
void GameScene::button_touch_test(Object * pSender){ CCLOG("button touched !"); }
创建3个MenuItemImage,再将这3个添加到menu中(最后一个NULL不可以省略掉)