我正在尝试创建一个简单的循环,该循环遍历 CCTMXTiledMap 中 CCTMXLayer 中的所有图块。我想要实现的只是打印出每个图块的位置,但对于我的生活,我无法弄清楚如何循环通过图块或如何访问它们的容器。我是一个objective-c新手,所以请温柔:)
请停下来!
到目前为止我所拥有的:
CGSize mapSize = [_tileMap mapSize];
CCTMXLayer *backgroundLayer = [_tileMap layerNamed:@"Background"];
int h = 0;
int w = 0;
NSInteger i = 0;
for(h = 0; h < mapSize.height; h++)
{
for(w = 0; w < mapSize.width; w++)
{
i = h * mapSize.width + w;
// I tried the following but none of it worked:
//CCArray* tiles = [backgroundLayer children];
//CCSprite *tile = [backgroundLayer tileAt:tileCoord];
//CCSprite*tile = [tiles objectAtIndex:i];
//CCNode* tile = [backgroundLayer children getChildByTag:i];
CGPoint position = [tile position];
[_debugHud addTileId:i at:position];
}
}