0

衝突検出のために、ボールの四角形が壁の四角形と交差していることを確認する必要があります。今は動作していますが、これを使用して、ボールの位置がタイルの GID の 1 つにあるかどうかを確認しています。

-(void) checkHits:(CGPoint)position {
    CGPoint tileCoord = [self tileCoordForPosition:position];
    int tileGid = [levelLayer tileGIDAt:tileCoord];
    //NSLog(@"%g",tileRect.origin);
    if (tileGid) {
        NSDictionary *properties = [level propertiesForGID:tileGid];
        if (properties) {
            NSString *collision = [properties valueForKey:@"break"];
            if (collision && [collision compare:@"True"] == NSOrderedSame) {
                //for blocks
                //[[SimpleAudioEngine sharedEngine] playEffect:@"hit.caf"];
                [levelLayer removeTileAt:tileCoord];
                velocity.y *= -1;
            }
            if (collision && [collision compare:@"False"] == NSOrderedSame) {
                //for edges 
                //[[SimpleAudioEngine sharedEngine] playEffect:@"hit.caf"];
                velocity.y *= -1;
            }      
        }    
    }
}

これを変更して、ボール rect/boundingbox がプロパティ break を持つタイル rects/boundingboxex (および最初にタイル rect/boundingbox を取得する方法) と交差するかどうかを確認する方法を知る必要があります。PS タイル マップ エディターを使用しています。

4

1 に答える 1

0

少し前にこれを考え出しました:

    CCSprite *tile;
    for (int i = 0; i < level.contentSize.width/level.tileSize.width; i ++)
        for (int j = 0; j < level.contentSize.height/level.tileSize.height; j ++){
            tile = [levelLayer tileAt:ccp(i,j)];
            if (CGRectIntersectsRect(ball.boundingBox, tile.boundingBox)) {
                //Do whatever...
            }
        }
    }

マップ作成を簡単にするために、衝突レイヤーを用意することをお勧めします。

于 2012-07-23T16:25:54.873 に答える