开发者

Assigning collision properties to layers on Tiled and using them in Cocos2D

I recently followed a tutorial on collision detection in Cocos2D in use with tmx files created in tiled: http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2

Although this will be very useful to me, I want to also be able to detect collision properties of tiles on an entire layer, instead of just detecting collision properties on individual tiles.

I noticed on Tiled that you can right click a layer and assign properties just like you can with an individual tile.

Inside a method in my code I have a way of checking a tile's properties:

CGPoint tileCoord = [self tileCoordForPosition:position];

int tileGid = [invisiblePropertiesLayer tileGIDAt:tileCoord];

if(tileGid){
    NSDictionary *properties开发者_开发知识库 = [theMap propertiesForGID:tileGid];

    if(properties){
        NSString *collision = [properties valueForKey:@"collidable"];
        if(collision && [collision compare:@"true"] == NSOrderedSame) {
            return;
        }
    }
}

Is there a way I can change this to check if I'm colliding with ANY tile on a particular layer? Thanks!


Someone else told me how to do it on another forum. It was easy as this:

    CGPoint tileCoord = [self tileCoordForPosition:position];

int tileGid = [blocksCollidable tileGIDAt:tileCoord];

if (tileGid)
    return;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜