白面小书生 2015-10-19 08:11
浏览 1017

cocos2dx3.4我一个按键触发发送一次消息,但是收到了三次消息,只是发送了一次

 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;
}
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序