0

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

1 回答 1

0

你看过下面的教程吗?

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

另外,那里还有很多其他很棒的。

于 2013-01-08T03:51:25.210 回答