Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

Source: Internet
Author: User


Well, I really don't understand it. I just wrote three classes now. Why have I reached Article 8? I think it's strange that I am simple and clear enough to speak. (Xiao RuO: I renew, please renew !)

 

Well, now that the main character can appear and operate, it is time to let the monster appear.

 

It's too easy to make a Monster appear. Isn't it just to write a Monster class, and then create a rigid body so that it can collide with the main character, and then let the main character buckle blood or add blood?

Yes, it is. But it is not important. I want to introduce that it is interesting to use the level editor to create all the monsters to appear ~

 

 

Amazing TiledMap

I don't know if you have read the example tutorial of my "run and run" game (well, it seems that it is widely spread, but there are many bugs). TiledMap is also introduced in "run and run, it should be said that it mainly introduces TiledMap to create a map.

 

In fact, TiledMap, as its name implies, is a lattice map. It is a map editor, but in fact it is a level editor, because a map is a level in a sense.

 

While writing "Don't save me", I have been struggling. Do I write the level editor myself, or do I manually configure the level?

Then, one morning, I sat in the garden to bask in the sun (very happy) and suddenly remembered -- TiledMap.

 

So let's see how to use TiledMap to configure level data for this game.

 

New TiledMap

Well, the tutorials I wrote are basically basic, so take care of friends who don't know TiledMap.

The official address of TiledMap is: http://www.mapeditor.org/

You can download and install it without any special attention.

 

Level background

First, you need to figure out that the game "Don't save me" has no map. Well, it has a circular and rolling map, but it does not need to interact with players. It just keeps rolling.

 

Therefore, when we use TiledMap to configure the level, it seems a bit tangled, because there is no map, there is no reference, we need to set the location of the monster out of thin air. (Xiao RuO: Do monsters have images? Who says there is no reference ?)

 

No, our monsters cannot have images when configuring checkpoints, because they don't appear all at once, they are not maps.

 

So we have to deal with it a little bit.

We run the game first, and then,

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

This game is our reference. How can we use it?

 

Open TiledMap, create a new map file, and set it to 480X800 :,

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

Well, save it habitually and name it "tg1.tmx"

 

Then, drag the game to the graph block window at the bottom right of the TiledMap editor,

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

In the last step, select the entire graph block, click in the map area of the editor, and add the graph block to the map area to overwrite the whole map,

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

OK. This is our reference object. It is only used to edit the level. When it comes to the game, it is not needed.

 

Start configuring monsters

For ease of explanation, I only create two types of monsters, one is bloody, and the other is bloody.

Correspondingly, there are two image resources ,:

Http://yunpan.cn/QNCpzpvRyQYqe access password 5d97

This is an image packaged with TexturePackage. The usage of this software is not described here.

 

OK. after the image is downloaded, save it to the resources. Then, drag the monster.png image to the graph block window of the TiledMap editor. Configure the attributes as needed ~ Casual (Xiao RuO: What is casual !) :

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

Then, just fill in the map area as you like, such as the one I entered:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

My art cells are more developed, so you don't have to feel inferior. Just practice more, well. (Xiao RuO: Is your art cell long ?)

 

All right, everything we have just done is not required during the game operation and is deleted. (Xiao RuO: You are here to play with us !)

 

Create a monster attribute Layer

OK. Next we will focus on creating a new map layer (a layer, not a new map file ).

On the right side of the TiledMap Editor, there is a layer window. Right-click there and add the object Layer:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

The name is called monster. You can do whatever you like (Xiao RuO: Can you do this? You are writing a tutorial ):

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

 

Add monster attributes

Okay, the next step is the focus (Xiao RuO: I mentioned it before and said it is okay)

Note that you have selected the monster Object layer (click it ).

 

There are a bunch of tools above the editor. We need to select the rectangle tool,

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

Then draw a rectangle in the map area. Do not make it too large:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

Then select the selection tool:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

Now, double-click the rectangle you just drew and the Properties dialog box appears. Then, follow the instructions below:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

The name is used to obtain the object in the program, and the object attribute is used as the configuration of the monster.

Here, I think everyone knows how to do it (Xiao RuO: Well, I don't know)

I don't know. Can I roll it out? The eighth episode is complete, and you are not conscious of it.

 

Okay. Now, create another rectangle as you just created the rectangle. The attributes are as follows:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

The name is still monster, and the id is changed to 2. showTime is liked by everyone. showTime is the number of seconds after which a monster will appear.

Then fill in the rectangles according to the monsters we created earlier, such as my:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

Note that you need to align the upper left corner of the rectangle with the central point of the monster (as far as possible, not too accurate ).

 

Okay. Save it.

Then, copy the edited tg1.tmx file to the Resources directory of the game and open it in a text editor (UltraEdit or others are recommended, rather than notepad). After opening the file, it is as follows:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

It's messy. It doesn't matter. Find the three points marked in the figure and delete them. It is the background layer of the reference object.

 

The final result is as follows:

Cocos2d-x3.0 game instance of "Don't save me" Article 8 -- TiledMap implementation level editor

A small piece is left.

 

Well, this is the complete level configuration process. Although you still need to manually delete something, it is much faster than manual configuration.

If you don't have enough time to compile the level editor for your own games, I think TiledMap is a good choice.

 

Next, we will start to use this level configuration file to load monsters ~

 

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.