Weird TMX map rendering

Weird TMX map rendering


Hello. I’m using TMXTiledMap object using ::createWithXML() and passing this mock into that function

  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  "<map version=\"1.0\" tiledversion=\"1.1.0\" orientation=\"orthogonal\" renderorder=\"right-down\" width=\"32\" height=\"32\" tilewidth=\"16\" tileheight=\"16\" infinite=\"1\" nextlayerid=\"2\" nextobjectid=\"1\">"
  " <tileset firstgid=\"1\" name=\"spritesheet_16\" tilewidth=\"16\" tileheight=\"16\" tilecount=\"3\" columns=\"3\">"
  "  <image source=\"spritesheet_16.png\" width=\"48\" height=\"16\"/>"
  " </tileset>"
  " <layer id=\"1\" name=\"Tile Layer 1\" width=\"16\" height=\"16\">"
  "  <data encoding=\"csv\">"
  //      "<chunk x=\"0\" y=\"0\" width=\"16\" height=\"16\">2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2</chunk>"
  //      "<chunk x=\"16\" y=\"0\" width=\"16\" height=\"16\">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,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,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,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,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,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,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,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,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,1,1,1,1</chunk>"
  "  </data>"
  " </layer>"

So, data is empty but here is what I see in the game

If I add something like this
"<chunk x=\"0\" y=\"0\" width=\"16\" height=\"16\">0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</chunk>"
(With random count of zeros not equal to chunk.height * chunk.width)
The picture differs drastically

If I uncomment first chunk (the most top of two commented lines) I see that

But if I uncomment both chunks I expect two squares like above with different tile type in each. Here is what I see

Weird tile at the bottom right and no chunk to the right of the first one

My tileset: spritesheet_16
What’s wrong with me or with cocos or with TMX plugin?

P.S. Red triangle is my character. Don’t pay attention on it and chunk position in each frame
I also noticed that if I just remove these commented lines there will be the first image but with another types of tiles in the same positions

This issue occurs only with infinite/chunked maps. Fixed map of any size works fine


Could you get me your source files and I’ll play with this?


Sure, check this out I’ve prepaired all needed things in HelloWorldScene.cpp including simple moving around with mouse clicks and predefined issue strings


I’m all but certain that the <chunk> element is not supported in cocos2d’s TMX parser?

You probably need to either try and change the map from “infinite” to a fixed size, or make a new map that has a fixed size.

If you really need non-fixed map size you’ll probably want to start writing your own tile/map format and renderer as the cocos2d one will not be of sufficient performance in its out-of-box state.

Edit: or best case you decide to be its supporter and add both parsing and rendering support for infinite maps using chunks into the cocos2d engine and submit it as a github PR :smiley:

Edit 2: oh, and also I’m not sure how well supported the external tileset feature is when using cocos2d’s parser/renderer. I hope its in there, but I would bet that it is currently not supported.


I’ll think about a PR :slight_smile: but for now I make custom handler of infinite world that will generate fixed-size chunks that look like an infinite world


Is there a way to “hot replace” TMX string in game?


I think your problem is related to Tiled 1.2 release which apparently breaks most of the existing tiled integrations to game engines.


Not sure what you want to do exactly or specifically, but in some sense I would say no. However, there are probably various means to your desired end. It will likely just require writing code to handle the modifications you want at runtime. If you want to pre-process replace text before parsing you should be able to load file into string, modify, and then create the map with an xml string instead of filename, for example.

As noted by the last reply, here is Tiled 1.1 if you want to use a more compatible version, or to be more specific a version that is harder to accidentally use newer unsupported features :smiley: . .

The only likely library that supports all features is the core Tiled app parser/renderer, but it is unfortunately somewhat intertwined with the use of Qt framework so it’s likely not an easy drop-in-place use case. .