【发布时间】:2011-04-06 17:31:51
【问题描述】:
我最近关注了一个关于在 Cocos2D 中使用 tmx 文件在 tiled 中创建碰撞检测的教程:http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2
虽然这对我来说非常有用,但我还希望能够检测整个图层上图块的碰撞属性,而不仅仅是检测单个图块上的碰撞属性。
我在 Tiled 上注意到,您可以右键单击图层并分配属性,就像使用单个图块一样。
在我的代码中的一个方法中,我有一种检查图块属性的方法:
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;
}
}
}
有没有办法可以更改它以检查我是否与特定图层上的任何图块发生碰撞?谢谢!
【问题讨论】:
标签: iphone cocos2d-iphone collision-detection layer