cocos2d-x获取按钮事件

//声明回调方法
void moveToLeft(Ref* sender);
void moveToRight(Ref* sender);
void quickMove(Ref* sender);

//按钮
auto leftBtn = MenuItemImage::create("arrow1.png","arrow1.png",CC_CALLBACK_1(TollgateScene::moveToLeft,this));
leftBtn->setPosition(Point(10,0));
auto rightBtn = MenuItemImage::create("arrow.png","arrow.png",CC_CALLBACK_1(TollgateScene::moveToRight,this));
rightBtn->setPosition(Vec2(150,0));
auto quickBtn = MenuItemImage::create("button1.png","button1.png",CC_CALLBACK_1(TollgateScene::quickMove,this));
quickBtn->setPosition(Vec2(450,0));
auto menu = Menu::create(leftBtn,rightBtn,quickBtn,NULL);
menu->setPosition(Vec2(100,60));
this->addChild(menu, 1);

//回调方法的实现
void TollgateScene::moveToLeft(Ref* sender){
  auto a = (Player*)this->getChildByTag(11);
  a->moveToLeft();
}
void TollgateScene::moveToRight(Ref* sender){
  auto a = (Player*)this->getChildByTag(11);
  a->moveToRight();
}
void TollgateScene::quickMove(Ref* sender){
  auto a = (Player*)this->getChildByTag(11);
  a->quickMove();
}

你可能感兴趣的:(cocos2d-x获取按钮事件)