1

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.

Abdalla
  • 2,071
  • 2
  • 16
  • 27

1 Answers1

1

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thank you very much. I tried with 200x200 tile map, and it also stops rendering at about y=80. The tilemap contains one layer that is all filled with tiles from the same texture. So I thought it is only about 16,000 not 65,536 tiles that can be rendered by cocos2d-x. I tried 125x125 and it worked correctly, but that is too limited to be believable. Am I doing something wrong? – Abdalla Dec 19 '13 at 09:40
  • Sorry, my bad. It's 65k vertices but each tile has 4 vertices so that makes 16k tiles. – CodeSmile Dec 19 '13 at 15:30
  • Contemplate splitting it into multiple tilemaps and loading/unloading them dynamically as your character gets near the edges. You should be able to deftly avoid these limits this way. – Shayne Mar 04 '14 at 10:08