Tiled Map Editor seems to not load properly with Cocos2d-x-4

I’ve posted this similar stack overflow post: “tiled - Loading and rendering a Tilemap TMX using Cocos2d-x-4 C++ - Stack Overflow

In short, I have a very simple test scene in C++ Cocos2d-x-4 that is loading a tmx file generated from Tiled.

– I’ve even following using the same sample png desert texture “tmw_desert_spacing.png” provided in the examples of Tiled Map Editor, – and it seems that it renders in Cocos2d-x-4 just very strange results.

  virtual bool init() 
  {
    auto map = TMXTiledMap::create("tmx/desert.tmx");
    layer = map->getLayer("Desert");

    auto& mapSize = layer->getLayerSize();

    auto visibleSize = Director::getInstance()->getVisibleSize();

    this->addChild(map);

    //map->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f);

    return true;
  }

Seen above, is just super simple code for loading in a tmx file.

Expected output:

But get output like this:
image

This issue is much more likely to be with Cocos’s loader than with Tiled, so you should probably report it to them, rather than as a Tiled bug.

It looks like the map data is all there and correct, but an empty tile is being inserted at the start of each row.

Does your TMX use the CSV layer data format, by any chance? If so, try changing it to one of the compressed formats and see if that fixes it. A while back, Tiled started adding line breaks to the CSV output, and I wonder if Cocos’s parser is broken in such a way that it somehow interprets line breaks or whitespace as 0s.

Thank you!
I went into the tmx file – removed all the whitespace from the generated CSV Layer data in the TMX file – and, viola, now cocos2d-x-4 loads the map correctly.

Completely silly that they have a bug in their code for whitespace.

You should report that to them xP

Removing whitespace manually sounds like a pain, so I still recommend using one of the other tile layer data formats instead of CSV (if Cocos supports other formats). As a bonus, the compressed formats produce much smaller files.

Done, submitted a post on it via their forum – Though after reading a bit, seems like Cocos has stopped all future updates for Cocos2d-x, and is only focusing on their Cocos Creator engine

:frowning:

Just slight update – yes saving in Compressed Base64 zlib format does work – so I’m glad about that.

However I was wanting to use the CSV specifically because I am using it as a learning tool – aka I’m teaching a course on it, and it’s much easier for newer programmers to have it human readable.

But yah, for now I’ll just have to make due with a different format.
Thanks for your help!

1 Like

I would recommend that you stop using cocos2dx and move to axmol. Cocos2dx is no longer going to be maintained, In other words, it is dead(it is pointless to report anything to the devs). But axmol,which is a cocos2dx fork,it really well maintained, updated frequently and with a growing community. For instance CSV works perfectly in axmol.

2 Likes