// 创建图片菜单按钮
MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, this, menu_selector(PopupLayer::buttonCallback));
menuImage->setTag(tag);
menuImage->setPosition(pCenter);
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(Node* pNode);
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)
{
// pickOnePlayerToGo();
}
}
但是调试发现调用了三次receivedMsg(Ref* data);test=3