1:在AppController的didFinishLaunchingWithOptions中,加入
[__glView setMultipleTouchEnabled:YES];
2:在CCLayer类中实现以下方法
头文件:
virtual void registerWithTouchDispatcher(void);
virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
virtual void ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
Cpp文件
void HelloWorld::registerWithTouchDispatcher(void)
{
CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);
}
......
#pragma mark - Touch Event
void HelloWorld::ccTouchesBegan(cocos2d::CCSet * pTouches, cocos2d::CCEvent * pEvent)
{
CCSetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
{
CCTouch* pTouch = (CCTouch*)(*iter);
......
}
void HelloWorld::ccTouchesMoved(cocos2d::CCSet * pTouches, cocos2d::CCEvent * pEvent)
{
}
void HelloWorld::ccTouchesEnded(cocos2d::CCSet * pTouches, cocos2d::CCEvent * pEvent)
{
}
void HelloWorld::ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
ccTouchesEnded(pTouches, pEvent);
}