Record all kinds of problems encountered on the road to learning cocos2d-x and their solutions. Continuous updates.
I. assertion TMX: Only 1 tileset per layer is supported crash:
This error occurs when I use tiledmap. The edited map in tiledmap uses multiple graph blocks on the same layer.
When a map is loaded, the assertion failure window is displayed, and the location where the map is destroyed is tracked:
CCAssert( m_uMaxGID >= m_pTileSet->m_uFirstGid && m_uMinGID >= m_pTileSet->m_uFirstGid, "TMX: Only 1 tileset per layer is supported");
From the prompts in the assertion, we can see that only one graph block set is supported on one layer.
That is to say, each layer in the editor can only use the graph blocks in one graph block set, rather than those in other graph blocks!
Solution: (1) Draw multiple graph blocks on the same graph block for use. (2) discard other blocks and use a specific block.
Ii. tileGIDAt:
We use tileGIDAt to obtain the ID of a graph block corresponding to a certain cell on a layer. What is GID? It can be understood as a globally unique ID, and there may be multiple graph block sets. Therefore, the ID of each graph block is not from the graph block set 1, 2, 3... This is followed by the last ID of the previous graph block set!
Therefore, to obtain the correct ID, we should:
cocos2d::CCTMXLayer *towerLayer = map->layerNamed("tower");cocos2d::CCTMXTilesetInfo *towerSet = towerLayer->getTileSet();int nGid = towerLayer->tileGIDAt(ccp(0, 0)) - towerSet->m_uFirstGid;if(nGid >= 0){}
First, obtain the first ID of the graph block set corresponding to this layer, and then subtract to obtain the correct ID.
On the way to learning, I will share with you.