Scrolling large tile map using cocos2d-x gives me black tiles where there should be green tiles

StackOverflow https://stackoverflow.com/questions/20593880

  •  02-09-2022
  •  | 
  •  

Pergunta

I am loading 400x400 tile map created using Tiled software. One tile is 120 pixels for total of 48000x48000 pixels.

I load like this

    regionMap->initWithTMXFile("background2.tmx");
    mapLayer->addChild(regionMap, 0, enTagTileMap);
    mapLayer->setAnchorPoint(CCPoint(0,1));

Then I scroll like this.

    mapLayer->setPosition(position);

When I vertically scroll to about this position, I do not get the tiles from the map anymore, I just get black tiles.

    x=0 , y=5483.748535

When I horizontally scroll, I do not get the same problem even when I reach this position.

    x=-48000, y=400

Thanks for advance.

Foi útil?

Solução

I think it's fair to assume that cocos2d-x's tilemap renderer is a direct port of the one in cocos2d-iphone. If true, they both have the same restriction of a maximum of 65,536 vertices (16,384 tiles) that can be displayed (not counting empty tiles).

Your tilemap is 400x400 = 160,000 tiles assuming there is only one layer and there aren't any "empty" tiles (empty == tile locations with GID value 0). That means about ten times the number of tiles cocos2d will/can render.

Cocos2d will just render up to 16,384 tiles and then stop, the remaining tiles will not be rendered so you'll see the background color (default: black).

A common but awkward workaround is to split the map into several TMX files and align them in code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top