Cocos2d-x  多点触摸



首先,我们要在.h文件中注册触摸事件的回调方法:

//声明多点触摸的回调方法
   void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
                                                     
                                                     
   void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
                                                     
   void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);



在.cpp文件中的boolHelloWorld::init()函数中添加:

//多点触摸只接受两个参数,不接收是否吞噬触摸事件的参数。
    CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);



//触摸开始的回调方法
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    CCTouch* touch = (CCTouch*)pTouches->anyObject();
    CCPoint p = touch->getLocation();
    CCLog("触摸开始");
}



//触摸移动的回调方法
void HelloWorld::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    CCLog("触摸点移动");
}



//触摸结束的回调方法
void HelloWorld::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    CCLog("触摸结束");
}


Hi,推荐文件给你 "多点触摸.zip" http://vdisk.weibo.com/s/Hiqx3