Here is the implementation of touchesBegan:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
cocos2d::NSSet set;
cocos2d::CCTouch *pTouch;
for (UITouch *touch in touches) {
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch);
int unUsedIndex = 0;
// it is a new touch
if (! index) {
unUsedIndex = [self getUnUsedIndex];
// The touches is more than MAX_TOUCHES ?
if (unUsedIndex == -1) {
return;
}
pTouch = s_pTouches[unUsedIndex] = new cocos2d::CCTouch();
}
float x = [touch locationInView: [touch view]].x;
float y = [touch locationInView: [touch view]].y;
pTouch->SetTouchInfo(0, x, y);
CFDictionaryAddValue(touchesIntergerDict, touch, [NSNumber numberWithInt:unUsedIndex]);
set.addObject(pTouch);
}
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesBegan(&set);
}
CFDictionaryAddValue is always called with “unUsedIndex” which can be 0 if index is not 0. I am not sure this is intended or not.