0

我正在CCSprite双击(应该代表炸弹),就像这样。

- (void)handleDoubleTap:(UITapGestureRecognizer *)doubletapRecognizer
{
    [self placeBomb];
}

-(void)placeBomb
{
    NSLog(@"Bomb placed");
    _circle = [[CCSprite alloc]initWithFile:@"Circle.png"];
    CGPoint circle0position = ccp(_cat.position.x , _cat.position.y);
    CGPoint c0TileCoordt = [self tileCoordForPosition:circle0position];
    CGPoint c0TileCoord = [self positionForTileCoord:c0TileCoordt];//Supereffective way to get rid of decimals
    _circle.position = c0TileCoord;
    [self addChild:_circle];
    id fade = [CCScaleTo actionWithDuration:3.5 scale:0];
    [_circle runAction:fade];
    [self performSelector:@selector(explosion) withObject:nil afterDelay:3];
}

然后我运行-(void)explosionwhich - 惊喜 - 使其爆炸,然后再次调用 checkForDamage 方法,该方法测试爆炸生命周期内爆炸区域内的碰撞。

问题是我不想限制炸弹(精灵)的数量,但是当我现在放置两颗炸弹时,第一颗炸弹的爆炸发生在第二颗炸弹的位置,我显然不能责怪,因为这就是我要求它做的事情。爆炸是基于_circle.position爆炸块大约三百行长,所以我不会在此处发布它(Heres pastebin 链接),但作为示例,我将发布checkForDamage。

-(void)checkForDamage //Gets called with CCTime on explosion
{
    bool playerHit = NO;
    CGPoint bombPos = [self tileCoordForPosition:_circle.position];

    for (int i = 0; i <= explosionLenght; i++)
    {        
        CGPoint playerPosF = [self tileCoordForPosition:_cat.position];

        int bombX    = (bombPos.x + i);
        int bombY    = (bombPos.y + i);
        int bombNegX = (bombPos.x - i);
        int bombNegY = (bombPos.y - i);

        CGPoint centre = bombPos;
        CGPoint top    = ccp(centre.x, bombY);
        CGPoint left   = ccp(bombNegX, centre.y);
        CGPoint bottom = ccp(centre.x, bombNegY);
        CGPoint right  = ccp(bombX, centre.y);

        if (CGPointEqualToPoint(top, playerPosF) || 
            CGPointEqualToPoint(left, playerPosF) ||
            CGPointEqualToPoint(bottom, playerPosF) || 
            CGPointEqualToPoint(right, playerPosF))
        {
            playerHit = YES;

            NSLog(@"Player hit, BOOL:%i",playerHit);
            [self unschedule:@selector(checkForDamage)];
            break;
        }
    }

    [self performSelector:@selector(stopCheckDamage) withObject:nil afterDelay:2];    
}

如何创建_circle炸弹的多个实例,以使我可以同时进行多次爆炸并检查损坏情况。我尝试使用for循环并使用标签创建精灵,但我不知道如何通过标签全局访问和执行精灵上的东西。我想过为每次爆炸制作不同的精灵,比如

if (explosion1exists) {explosion with circle1}, if (expl1 + expl2 exists) {expl with circle3}

但是因为我最多会放置大约 20-30 颗炸弹,这是非常无效的,我认为必须有更好的方法。有什么方法可以有效地做到这一点?

4

0 回答 0