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

时间:2013-11-20 13:08:43

标签: c++ cocos2d-x

在我的项目中,我有一个包含大量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;
}

1 个答案:

答案 0 :(得分:0)

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