Only one tile shows up in tiledmap

I’ve made an extremely simple tileset and tilemap with Tiled 1.4.3, with one layer that has two small PNG tiles. When I try to use it in cocos2d-x-4.0 on Android, only one of those two tiles is rendered, and it’s the wrong one.

Tileset:
<?xml version="1.0" encoding="UTF-8"?> <tileset version="1.4" tiledversion="1.4.3" name="tileset" tilewidth="128" tileheight="128" tilecount="2" columns="0"> <grid orientation="orthogonal" width="1" height="1"/> <tile id="0"> <image width="128" height="128" source="tile-blue.png"/> </tile> <tile id="1"> <image width="128" height="128" source="tile-red.png"/> </tile> </tileset>

Tilemap:
<?xml version="1.0" encoding="UTF-8"?> <map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="128" tileheight="128" infinite="0" nextlayerid="2" nextobjectid="1"> <tileset firstgid="1" source="tileset.tsx"/> <layer id="1" name="Tile Layer 1" width="12" height="10"> <data encoding="csv"> 1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,2,2,2,2,1,1,1,1, 1,1,1,2,2,2,2,2,2,1,1,1, 1,1,2,2,2,2,2,2,2,2,1,1, 1,1,2,2,2,2,2,2,2,2,1,1, 1,1,2,2,2,2,2,2,2,2,1,1, 1,1,1,2,2,2,2,2,2,1,1,1, 1,1,1,1,2,2,2,2,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1 </data> </layer> </map>

What it looks like in Tiled:
tilemap

How I’m adding it in cocos2d-x:
auto map = TMXTiledMap::create("tilemap.tmx"); addChild(map);

How it’s rendering on my device:

can you double-check this example with your process?

You should select Base64 (zlib) as Tile Layer format, then it will work fine.
image

2 Likes

Some serious tile map chops @smitpatel88

ha ha
It was for Brick Breaker game so…

Switching to “Base64 (zlib compressed)” had no effect.

The tile map tests that come with cocos2d-x work fine, as far as I can tell. (I have nothing to compare them against, so I don’t know if tiles are missing or wrong. But it seems okay.)

Are there any ways your code differs from the example in cpp-test?

pls share here, will check

<?xml version="1.0" encoding="UTF-8"?> <map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="128" tileheight="128" infinite="0" nextlayerid="2" nextobjectid="1"> <tileset firstgid="1" source="tileset.tsx"/> <layer id="1" name="Tile Layer 1" width="12" height="10"> <data encoding="base64" compression="zlib"> eJxjZGBgYKQAM6FhUtTi04NLLS49tFZPqvvJCR9aYAChCACl </data> </layer> </map>

This is not supported properly.
Pls search forum.


Also

I’ve figured out the problem. Cocos2d-x can only read one image file for a tilemap. My tileset used two. So I combined tile-red.png and tile-blue.png into one image called tiles.png:
tiles

The tilemap works when tileset.tsx contains this:

<?xml version="1.0" encoding="UTF-8"?> <tileset firstgid="1" version="1.4" tiledversion="1.4.3" name="tileset" tilewidth="128" tileheight="128" spacing="0" margin="0"> <image width="256" height="128" source="tiles.png"/> </tileset>

So it is not correct to say that Cocos2d-x doesn’t support .tsx files; however, with a file that short, there’s really no need for it.

So here’s a complete working tilemap.tmx:
<?xml version="1.0" encoding="UTF-8"?> <map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="128" tileheight="128" infinite="0" nextlayerid="2" nextobjectid="1"> <tileset firstgid="1" version="1.4" tiledversion="1.4.3" name="tileset" tilewidth="128" tileheight="128" spacing="0" margin="0"> <image width="256" height="128" source="tiles.png"/> </tileset> <layer id="1" name="Tile Layer 1" width="12" height="10"> <data encoding="base64" compression="zlib"> eJxjZGBgYKQAM6FhUtTi04NLLS49tFZPqvvJCR9aYAChCACl </data> </layer> </map>

1 Like