MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, CC_CALLBACK_1(PopupLayer::buttonCallback, this));
void PopupLayer::buttonCallback(cocos2d::Ref *pSender){
Node* node = dynamic_cast<Node*>(pSender);
CCLOG("touch tag: %d", node->getTag());
if (m_callback && m_callbackListener){
(m_callbackListener->*m_callback)(node);
}
//this->removeFromParentAndCleanup(true);
}
其中m_callback是指向buyLandCallback的
void GameBaseScene::buyLandCallback(Node* pNode)
{
if(pNode->getTag()==Btn_OK_TAG)
{
switch(popDialog->getDataTag())
{
case MSG_BUY_BLANK_TAG:
landLayer->setTileGID(player1_building_1_tiledID,ccp(buy_land_x,buy_land_y));
break;
case MSG_BUY_LAND_1_TAG:
{
break;
}
}
log("faxongxiaox---->");
popDialog->setVisible(false);
//pNode->getParent()->getParent()->removeFromParent();
NotificationCenter::getInstance()->postNotification(MSG_PICKONE_TOGO,String::createWithFormat("%d",MSG_PICKONE_TOGO_TAG));
}else
{
log("faxongxiaox1---->");
popDialog->setVisible(false);
//pNode->getParent()->getParent()->removeFromParent();
NotificationCenter::getInstance()->postNotification(MSG_PICKONE_TOGO,String::createWithFormat("%d",MSG_PICKONE_TOGO_TAG));
}
}
void RicherGameController::receivedMsg(Ref* data)
{
static int test=0;
test++;
log("tesrt=%d",test);
int retMsgType=((String*)data)->intValue();
if(retMsgType==MSG_PICKONE_TOGO_TAG)
{
if(test==1)
pickOnePlayerToGo();
if(test==3)
test=0;
}
}