In the previous article, I taught you some basic rules and precautions for setting tilemap blocks.
This article teaches you something complicated:
How to make some event judgment through the ID of the map block.
Here we first explain what the block ID is:
When you load a map image, you can set the size of the image chunks to cut a map image into many small blocks. These blocks are automatically compiled into a one-dimensional array starting from 0, as shown below
Step 1: first solve the first problem: how to obtain the block ID
Because the image block is first painted on the layer, we must first find the corresponding layer.
View
Source
Print?1.
Map
= Cctmxtiledmap: Create (
"Maps/test2.tmx"
);
2.
Cctmxlayer *
Using lay = map-> layernamed (
"Layer0"
);
OK. Now, we need to determine the layer of the map ID through the layer name layer0.
Corresponds to the tags in the editor.
Now that we get the layer, we have to find the corresponding ID.
Step 2:
It is also very easy. If we want to get the ID of the map block in five rows and six columns of the layer, www.it165.net
View
Source
Print?1.
Ccpoint
Pp = CCP (
6
,
5
);
// Here, the first parameter is the number of columns and the second parameter is the number of rows. Please note that
2.
Unsigned
Int
ID
= Layer0-> tilegidat (PP );
OK. Now the ID is the index value of the graph block.
The same is true if you want to obtain the index value of the graph blocks on other grids of other layers.
What can I do with this value ??
Example:
1. Do walk blocking. For example, I decided that if all the graph blocks with an index of 5 on the map cannot walk.
2. Change the graph block. For example, if I set all the grids with the ID of 5, they will not be displayed.
....
And so on. We can use different games for many purposes.
This article is from the "Dairy" blog