我想知道当我在cocos2d中同时触摸2个精灵时,我怎么能检测到。我创建了一个类似于水果忍者的游戏,当我用刀片同时粉碎两个精灵时,我想添加一些奖励积分。我尝试了类似的东西,但它不起作用:
(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//Add a new body/atlas sprite at the touched location
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
//[self addNewSpriteAtPosition: location];
[_blade dim:YES];
[_bladeSparkle stopSystem];
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
if (b->GetUserData() != NULL) {
PolygonSprite *sprite = (PolygonSprite*)b->GetUserData();
NSLog(@"sprite entered, exited %d, %d",sprite.sliceEntered,sprite.sliceExited);
if(sprite.type == kTypeTrapPrice && CGRectContainsPoint(sprite.boundingBox, location))
{
NSLog(@"TOUCHED");
noTouch++;
}
}
}
}
// NSLog(@"NO TOUCH %i",noTouch);
[self clearSlices];
}
答案 0 :(得分:0)