cocos2d检测2个精灵中的同时触摸 - 就像水果忍者游戏一样

时间:2013-01-07 20:14:30

标签: iphone cocos2d-iphone touch sprite

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

1 个答案:

答案 0 :(得分:0)

您是否看过以下教程?

http://www.raywenderlich.com/14302/how-to-make-a-game-like-fruit-ninja-with-box2d-and-cocos2d-part-1

此外还有许多其他伟大的。