一、设置屏幕是可触摸的,添上一句话
setTouchEnabled(true);
二、注册单点触摸事件
void registerWithTouchDispatcher()
{
CCDirector
*pDirector=CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this,0,true);
}
addTargetedDelegate(this,0,true) 最后一个参数设置为true表示当前层接收到后终止不在向其他层传递。
三、从写需要的单点事件
bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
return
true;
}
void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{
}
void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
}
cocos2d-x 单点事件用法,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/liwenxue88/p/3749684.html