Playing games is a very important part. If this step is missing, it is difficult to make a good game. For cocos2dx, there are a lot of 2D map editors that can be used and the effects can be improved, among them, Tiled supports better, it supports several Tiled editing modes, such as normal, 45 degree map, etc.
If you want to make a small mobile game, the normal mode is enough. cocosdx supports well. If you want to have a 3D sense, you can use a 45-degree normal map. However, if you want to make a large scenario, for example, with a basemap of 4000*4000 pixels, you can use the Staggered mode. However, the cocos2dx encapsulation does not support this mode and you need to modify the source code for transformation.
Here I will not go into the detailed steps. Some experts have already written on the blog. I will link them here!
Enable cocos2dx to support tmx in Staggered format
The other blog provided by him is the * path finding algorithm code in the staggered mode.
Cocos2dx 45-degree Staggered format A * path Manhattan algorithm (to be optimized)
One thing to note is that I found a problem with his algorithm in practice and did not consider the cocos2dx coordinate system. The following is an example of my implementation code, at last, I will put my encapsulated code on CSDN and share it with you.
CCPoint CCTMXLayer::positionForStaggeredAt(const CCPoint& pos){CCPoint xy = CCPointMake((pos.x * m_tMapTileSize.width) + ((int)pos.y % 2) * m_tMapTileSize.width / 2,(m_tLayerSize.height - (pos.y + 1)) * m_tMapTileSize.height/2 - m_tMapTileSize.height/2);return xy;}
I wrote A * algorithm myself, but after porting it to cocos2dx, I found that the movement was not smooth and the code in the staggered mode was hard to understand, I don't know why the people who design such maps are so complicated in their coordinate transformation. I always don't feel very good at using this map.
Finally, let's talk about the defects of cocos2dx + tiled. Maybe I am not very familiar with it!
1. I think the texture map mode is not very friendly. It is good for a normal 90-degree map. For a 45-degree map, each TILE must be pasted separately. This is too troublesome. Imagine 4000*4000, how many times must be pasted, and a large block texture should be supported.
2. cocos2dx supports tiled. Only one image is supported for each layer. Because TMXLayer is implemented using CCSpriteBatchNode, this limitation has a great impact on the big map, if you use an integral graph of my 4000*4000 image, you can stop when the mobile phone cannot support images larger than 2048*2048. A layer is layered without an integral graph. After the layer is layered, a large amount of redundant tile is generated, and the memory is increased by half, exceeding 100 MB.
Let's take A look at my current achievements. At present, we have implemented functions such as scenario blocking, character occlusion, and A * path searching! At present, I am not very satisfied with this. I may rewrite a dedicated 45-degree map editor later.
I want to share the encapsulated code with you! If you have any questions, please contact me!
Cocos2dx use TiledMap to create resources for a 45-degree oblique map scenario