参考资料:http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_Enable_Multi-Touch/diff/4
在初始化代码中,开启当前层接受触摸
this->setTouchEnabled(true);
在AppController.mm文件中,设置开启多点触控
[__glView setMultipleTouchEnabled:YES];
测试一下,重写ccTouchesMoved函数,打印多点触控的位置
void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent){ if(pTouches->count() >= 2) //多点触控 { CCSetIterator itor; for( itor = pTouches->begin(); itor != pTouches->end(); ++itor) { CCTouch *pTouch = dynamic_cast<CCTouch *>(*itor); //获得游戏坐标位置 CCPoint ccp = pTouch->getLocation(); printf("%f\t%f\n", ccp.x, ccp.y); } printf("\n"); } else //单点触控 { CCTouch *pTouch = dynamic_cast<CCTouch *>(pTouches->anyObject()); CCPoint ccp = pTouch->getLocation(); printf("%f\t%f\n", ccp.x, ccp.y); }}
联系客服