在初始化代碼中,開啟當前層接受觸摸
- 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);
- }
- }
沒有留言:
張貼留言