【问题标题】:cocos 2d detect simoultaneous touch in 2 sprites - like in fruit ninja gamecocos2d 检测 2 个精灵中的同时触摸 - 就像在水果忍者游戏中一样
【发布时间】:2013-01-07 20:14:30
【问题描述】:

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

【问题讨论】:

  • 实际发生了什么?为什么它不起作用?

标签: iphone cocos2d-iphone touch sprite


【解决方案1】:

你看过下面的教程吗?

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

此外,还有很多其他很棒的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多