Tiled Map rendering problem?

Tiled Map rendering problem?

I’ve a strange problem with a map. I will try to explain it with an example.
This is part of my map:

When I load it, it works. I can see the map.
But if I change some tiles by another ones, for example like this:

I can’t see the green background anymore and that tiles/sprites are badly drawn. Result:

I only replaced some tiles by another ones, in the same Layer.
The draw problem sounds like a bug? I’m using Tiled 1.2 but i also tried with Tiled 1.0


My tiles are in .png format.
But I tried converting to .jpg and this is the new result:

Am I doing something wrong? Or it’s a bug?
cc @stevetranby @vkreal2 @smitpatel88 @zhangxm

Can you explain this a little bit?
Do you have a small code snippet showing how you do this?
It might be the map/layer trying to access a different texture which is not how these tile maps work…

1 Like

@tdebock i’m loading the map with the class cocos2d::TMXTiledMap and I’m not making nothing strange in the code. The problem is when I edit some tiles in the tool Tiled.

I think the code isn’t the problem because with some tiles it works perfectly, and with others not. The code is the same. I wonder if the tiles images must have some special settings for be loaded by the TMX cocos class :confused:

For example, this tile is perfectly drawn by cocos TMX class:


But this tile not:


I’m testing it with a 32x32 map and 32x32 px tiles.

Check the .tmx file… there will be a file path to the tilesheets (image files). In Tiled, this is generally a relative file path… ie: like ‘/…/…/SomeFolder/sheet.png’.
This will make it hard for the cocos2d-x project to find/use as the paths are different.

I assume this might be the issue. A small recommendation… ALWAYS put the image for tiles in the same folder as the .tmx file you are creating, and everything should work.

edit: In the tmx file… Look for a <image source="SOME_FILE" width="SOME_WIDTH" height="SOME_HEIGHT"/>

Make sure the file is not a relative path, just the filename itself is needed for cocos to read it.

@tdebock the collection of tiles pngs, the file .tmx and the file .tsx are in the same folder (Resources).

All files are in the same folder, I don’t have “image source”. I have the tileset tag:
<tileset firstgid="1" source="TileSetAspalt.tsx"/>

Maybe is because you’re using an old Tiled version. But I tried with an old version, and I get the same results. Help :frowning:

Anyway you can zip a folder with the .tmx file and the image assets? And put it on a public dropbox, hard to do any further assessment without digging in. Another thing you could (should) do, is to breakpoint into the Tilemap class from cocos, and step through the functions, make sure everything seems right in memory etc. Are there any warnings/errors logged to the console when this happens?

Ok, here I attach an example.

Map.zip (9.8 KB)

Please, create an empty project and try to add that map, and tell me if you can see this tiles on the map:
Aspalt05 Aspalt06

You can play changing the tiles, etc. In my case, inside the game, I only see this tile:

This is how i’m creating the map:

Vec2 origin = Director::getInstance()->getVisibleOrigin();
cocos2d::TMXTiledMap* tiledMap = new cocos2d::TMXTiledMap;
tiledMap->setPosition(origin.x, origin.y);
scene->addChild(tiledMap, 0);

Original map:

Result in iPhone:

Tested in iPhone 7.
Tiled 1.2
cocos2d-x 3.17

I also tried to add the road tiles in a different Layer. Same results.

How did you create the asset? Xcode/iOS can have some issues with certain pngs that have additional meta data in the file.

My designer made the assets, with a designers program, i don’t know which.
Can you create an empty project and test the map? It takes 5 minutes :stuck_out_tongue:
For make sure that you’ve the same problem. I don’t know… it sounds like a problem in cocos class. It sounds like cocos has problems for draw some special tiles/sprites…

Didn’t show up for me either. I do know a TMXLayer is a BatchNode, so it uses a single texture… I see 3 different textures.

Simple texture? Obviously, I need to draw a map. I’ve a lot of tiles/sprites for draw the map. I can’t draw a map with only 1 png/tile.

I meant per TMXLayer. 1 Texture per layer. (can have 1 texture for all layers, but not many textures for 1 layer)

class CC_DLL TMXLayer : public SpriteBatchNode

I tried to put each tile/png in different layers. I made 3 layers. Each one per tile.
Same results…

Got this on my iPhone. I created a new .tmx file (attached below). I got an ‘version unsupported’ error in my console log with your tmx file. I am using v3.13 though, rather old.

Map2.zip (4.1 KB)

Also… please (unless you are doing manual memory management)… allocate the map with cocos2d-x create methods for autorelease.

tilemap = TMXTiledMap::create("file.tmx");

Let me know if that worked. I just created a new tmx file in tiled with base64 (zlib compressed) and put each texture on its own layer, without the .tsx, just added each tileset separately

I tested both changes:

  • base64 (zlib compressed)
  • tilemap = TMXTiledMap::create("file.tmx"); (without allocating memory manually)

Not works. Same results.

Now I tried with this 2 changes:

  • Add each png/tile without .tsx. I mean, embed each png in the map separatly.
  • Add 1 layer per each type of png/tile.

Now works.
Thanks you @tdebock :slight_smile: you helped me to discover the problem.

The question is when cocos team will update the class TMXTiledMap for support .tsx files.

Currently is very tedious design a map. It’s crazy.
I don’t want to add each tile/png separatly and 1 layer per type of tile.
I would like to work with .tsx files and add the amount of layers that I want. I don’t want to be obliged to add one layer per type of tile. :disappointed_relieved:

This disappoints me because of the importance of tiled maps. Is very common to make a game with a tiled map. The cocos team should prioritize this update. :confounded:

1 Like

Thanks. Have you created a GitHub issue yet for this?

1 Like