我想知道如何在 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];
}