need a crash course of making a map editor

Started by
7 comments, last by Instruo 18 years, 8 months ago
I am making a rts game. I can display maps(with layers and animation), sprites,menues and avis. So I got the gfx part mostly done. So instead of wrighting out the map by hand I am trying to make a map editor. I am getting stuck on how I can click on a tile from my tile bar and then click on the map and place that tile. any one know how I could do that?
Advertisement
has any one ever made a map editor?
I'm assuming from what you've written that you're using a tile based map. So, what you need to do is:

- Have the user select a tile somehow. It sounds like you've thought of having a menu bar for this.

Basically you'll need a variable of some sort that tells you what tile (or tile type if your editor is going to randomly choose a tile of a certain type) that is set when the user selects the type of tile they want. If you want to be a little fancy, you can have a semi-transparent copy of the tile attached to the mouse cursor at this point.

- The user needs to be able to draw the tile onto the map somehow.

Most people will have thier editor display either an empty grid, or a map filled with default tiles, or if you like, a map filled with default tiles with a grid drawn over it. When the user clicks somewhere on the map, you determine which tile they have just clicked on (Find the screen coordinates, use those to find world coordinates, identify which tile it is - just like figuring out what tile a click was on in game), and replace the tile with the one the player has selected.

- If you want an undo feature, store the type of tile currently in a cell before replacing it with the one the user has selected.

- Once the user is done, the editor will write out the data to a file that the game can then read in.

Does that help you at all?

- Jason Astle-Adams

If you know how to detect the position of the mouse when you click, you can determine which tile in the tile bar that was clicked and you can store that (and highlight it for the user if you wish).

Then when they click on the regular map, you update that tile with the one in the tile bar (that you stored previously).

-----------------------------

I have a level editor I made for pacman a long time ago.
If you want to have a look, I have it here but it probably won't be helpful.
If you're using a GUI Library for your editor you don't have to worry about which tile was selected, the only "problem" would be, where the tile is placed by the user and that's not that difficult, because you only have to translate the mouse position to the selected tile (I think you have that code already in your game).

From your posting I assume you don't have much experience in programming GUI software, I think it's a good time now to learn it :)
I am making my map/level editor from scratch. The only api's I am using is win32 api and directdraw api.

Things I know.
A) find the mouse position
B) tell if left button pressed
C) Draw a defualt tile to the map arreya
D) Draw the tiles to the tile bar.


Things I need to find out
A) How to save the map data with layers
B) How to attache a tile to the cursor
C) To place the slected tile on the map
Quote:Original post by kingpinzs
A) How to save the map data with layers
If you plan on saving the maps as files, I would recommend taking the serialization approach. It pretty much saves the whole class as binary data on your disk so it makes it very fast for loading and saving. The only negative effect of this approach is that you're forced to make your own custom map editor for the data format.

Quote:Original post by kingpinzs
B) How to attache a tile to the cursor
C) To place the slected tile on the map
You could have a "toolbox" and when they click on the toolbox, the selected tile is choosen. Then when the click on the "Map View", the tile is placed onto the tile location that they clicked on. The hardest thing about this is designing the workable GUI for your application.

Another alternative would be to use a third party map editor like Tile Studio or Mappy. You'd have to use some of their code to load the file format, but other then that, I'm pretty sure it's a valid solution. [smile]
Rob Loach [Website] [Projects] [Contact]
Well I am programming the map editor to learn more about programming to be able to make all my own tools.

I know the basics of what needs to be done just not how to do it.

Any one know were I can find tuts on making map editors?

seems to me that these fine fellows have told you what you need to do to make it. the next step for you is to take the ideas they gave you, consider your design, look at your API/language for which tools that are available to you would be likely to help, and put it together. Some things to consider:

Quote:
C) To place the slected tile on the map

Look at your design, how are you keeping track of the tiles of the map? A 2-dimensional array? How wide is an individual tile? Let's try a simple example:

Assume we have a 2-dimensional array storing one of two tile types for each tile. Let's say 0 = grass and 1 = dirt. Each tile is 10x10 pixels and our map is 4x4, thus each tile can be referenced as so:
[0,0]   [0,1]   [0,2]   [0,3][1,0]   [1,1]   [1,2]   [1,3][2,0]   [2,1]   [2,2]   [2,3][3,0]   [3,1]   [3,2]   [3,3]


So, an all grass map would "look" something like this:
[0]   [0]   [0]   [0][0]   [0]   [0]   [0][0]   [0]   [0]   [0][0]   [0]   [0]   [0]


And a mixed map would "look" something like this:
[0]   [0]   [0]   [1][1]   [0]   [1]   [1][0]   [1]   [0]   [1][0]   [0]   [1]   [0]


Using the layout given above, referencing the array element in [0,3] would give you 1 (dirt) and referencing [1,1] would give you 0 (grass).

Now, if I wanted to change [1,1] to dirt, all I'd have to do is change its value from 0 to 1.

So, how can we tell it was [1,1] that was 'clicked' on? That's simply a matter of some simple math. For simplicity's sake, we'll assume that our mouse coords are relative to the Window (so, X: 0 Y: 0 is the top, left corner of the window) and that the tiles start right there.

So, say we have a click at X: 15 Y: 19
What we need to do is scale those numbers down so that they're relative to our tile array. We know that each tile is 10x10 pixels, so our tile in [0,0] covers the area from {0,0} to {9,9}, our tile in [1,1] goes from {10,10} to {19,19} and so on.

We'll start by figuring out just the X coord, using a nice little trick:

We take our X: 15 and divide it by our tile width of 10. In floating point numbers, this gives us 1.5. If we cast that to an int, thus truncating it (getting rid of the numbers beyond the decimal point), we have the X index into our tile map. We can do the same thing with our Y value, and voila! We have our map index of [1,1]. When in doubt, always double check against one you've figured out manually, like above ([1,1] goes from {10,10} to {19,19}). Now knowing which tile was clicked, we can change its value to the type of tile we desire.

In a real world example, its a little more complicated because your tiles aren't always going to start in the top-left corner, etc, so you'll have to take that into account before you get your array coords. Once you get your mouse position relative to the tiles, however, you should be good to go!

Hope that helps :)

"Game Programming" in an of itself does not exist. We learn to program and then use that knowledge to make games.

This topic is closed to new replies.

Advertisement