C++ 在cocos2d-x cpp项目中的移动层内处理触摸事件?

C++ 在cocos2d-x cpp项目中的移动层内处理触摸事件?,c++,cocos2d-x,C++,Cocos2d X,在我的项目中,我有一个包含很多CCLabelTTF的层。图层可以向左或向右移动。我已经实现了三个ccTouch事件。现在我想在每个CCLabelTTF中添加触摸事件。当用户触摸CCLabelTTF并进入另一个场景时。我能做什么? 谢谢你 bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); void ccTouchMoved(CCTo

在我的项目中,我有一个包含很多CCLabelTTF的层。图层可以向左或向右移动。我已经实现了三个ccTouch事件。现在我想在每个CCLabelTTF中添加触摸事件。当用户触摸CCLabelTTF并进入另一个场景时。我能做什么? 谢谢你

bool  ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
void  ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
void  ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);

详情如下:

bool  WallScene::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
touchbeginpoint = ccp(pTouch->getLocation().x , pTouch->getLocation().y);
touched=true;
return true;
}
void  WallScene::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
touched=false;
}
void  WallScene::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint newpos=ccp(pTouch->getLocation().x , pTouch->getLocation().y);
CCPoint temppoint=ccp(newpos.x-touchbeginpoint.x, newpos.y-touchbeginpoint.y);
changepoint =ccp(changepoint.x+temppoint.x, changepoint.y+temppoint.y);
////////////////
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();

if(changepoint.y!=0)
    changepoint.y=0;

if(changepoint.x>=0)
    changepoint.x=0;

if (changepoint.x<=-3000*rescale+visibleSize.width)
    changepoint.x=-3000*rescale+visibleSize.width;
////////////////
this->setPosition(changepoint);
touchbeginpoint = newpos;
}
bool wallsecene::CCTouch开始(CCTouch*pTouch,CCEvent*pEvent)
{
touchbeginpoint=ccp(pTouch->getLocation().x,pTouch->getLocation().y);
触摸=真实;
返回true;
}
void wallsecened::ccTouchEnded(CCTouch*pTouch,CCEvent*pEvent)
{
触摸=假;
}
void wallsecene::ccTouchMoved(CCTouch*pTouch,CCEvent*pEvent)
{
CCPoint newpos=ccp(pTouch->getLocation().x,pTouch->getLocation().y);
CCPoint temppoint=ccp(newpos.x-touchbeginpoint.x,newpos.y-touchbeginpoint.y);
变更点=ccp(变更点.x+临时点.x,变更点.y+临时点.y);
////////////////
CCSize visibleSize=CCDirector::sharedDirector()->getVisibleSize();
if(changepoint.y!=0)
变化点y=0;
如果(changepoint.x>=0)
改变点x=0;
if(changepoint.xsetPosition)(changepoint);
touchbeginpoint=newpos;
}

创建CCLabelTTF的子类,覆盖该类中的touch方法,并在这些方法中执行任何您想执行的操作。

有没有理由不将CCMenuItemLabel对象与CCLabelTTF一起使用CCMenu?@YvesLeBorg我有太多标签,以至于无法将它们全部放入CCMenu。这就像说“我有太多精灵,我不能”将它们全部放在一个应用程序中,“…你将标签作为子项添加到某个应用程序中,有什么区别?