Advanced usage of tilemap map editor in cocos2d-x)

Source: Internet
Author: User

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 that2.UnsignedInt 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.