Vol*_*ort 3 objective-c cocos2d-iphone
我设法遍历Tiled图层中的所有CCSprites(tile).但是,我真正需要的是迭代图层中所有图块的所有属性(NSDictionaries).我该怎么做?我真的不需要获取CCSprites,只需要获取属性列表.
您需要使用-(NSDictionary*)propertiesForGID:(unsigned int)GID方法CCTMXTiledMap来获取tile属性.
但首先你需要知道瓷砖的GID.从以下-(uint32_t) tileGIDAt:(CGPoint)pos方法获取CCTMXLayer:
CGPoint pos = ccp(2,1);
uint gid = [layer tileGIDAt:pos];
if (gid > 0) {
NSDictionary *tileProperty = [tiledMap propertiesForGID:gid];
// do stuff here
}
Run Code Online (Sandbox Code Playgroud)
编辑:这里是如何迭代所有瓷砖CCTMXLayer:
for (NSUInteger y = 0; y < tmxLayer.layerSize.height; y++) {
for (NSUInteger x = 0; x < tmxLayer.layerSize.width; x++) {
NSUInteger pos = x + tmxLayer.layerSize.width * y;
uint32_t gid = tmxLayer.tiles[pos];
if (gid > 0) {
NSDictionary *tileProperty = [tiledMap propertiesForGID:gid];
// do stuff here
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1495 次 |
| 最近记录: |