Creating a 2D Tile Map editor

Hey everyone, I have been creating a 2D tile map editor on and off for a while now but Im starting to have a bit of trouble implementing some things. Firstly, I want to be able to import tile images or something so i can create different style maps but im not sure how to import different images and where to place them if you know what i mean. Like right now i just have buttons that I click to switch to different tiles but its all static…

Also im trying to make a scrollable JPanel (the panel on which im drawing the tiles).

I have the class that extends JPanel which is put on the frame in the center of a JFrame that has a border layout, so it is resized to fit the screen. Im not quite sure how I could add the JScrollPane to the JPanel to make it work (I have tried quite a few things but nothing seems to work).

http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html

just wrap the JPanel in a JScrollpane.

add(new JScrollpane(panel));

I tried that so many times and it didnt work, but for some reason when you posted it, i tried again and saw the light, i was adding the JScrollPane in the class that extended JPAnel, rather than doing it in my class that extends JFrame.

THANKS!

Hi,

You should check out this tile map editor: http://www.java-gaming.org/forums/index.php?topic=18068.msg142928#msg142928

Maybe you could build on the great stuff Juddman has already done, he’s using Swing just like you. :slight_smile:

Best wishes,
Keith

Thanks man im gonna look throught the source to see how he did some things but i just want to create my own just for learning…Thanks a lot for that though:)

I would recommend developing the map editor and the game at the same time. Then you can use the same engine for both and just have some separate code for the game loop and the map editor “stuff”.

In the map editor I made a while back, I defined the image filenames for different times of maps in separate files (specially formatted text files). Each type of object (e.g. treasure chest, door) used a specific image in the file. Some special objects allowed selection of a special image within the editor.

I think a better option would be to include the tile definitions in the map editor somehow. It would probably be some kind of text field with browse button kind of thing. Or (even better if there’s enough room) it could display the image instead of having the text field. The values could be imported and exported if you wanted to make them independent of the map.

Well im not quite sure what you mean by make the game and map editor at the same time so they can use the same “engine” because im not really quite sure what the engine is in my game lol. For me, I just start writing the game and thats about it lol (might be my flaw). For example, I am writing my tower defense game, I dont really have an engine for it, i just started from scratch and wrote the tower of defense game. But my map editor is universal for the way I write my games. I just create the map in the map editor, generate it and it sends it to a txt file (formatted in java 2D aray) and i just paste that in my Map class and use it like that :-…

If you can explain to me what the engine of my game is, or what it would be I would really appreciate it because I have been quite confused in this subject for quite a while.
Like what classes would the map editor and the game loop have in common that they both use?

Also, when you say make them together so they can use the same engine do you mean I should make the MapEditor part of the game and lets say if i start the game, go to map editor i can essentially change the map “live”?

(really sorry about these questions, im not really a beginner but never understood engines and all that).

The rendering and map data structures. Both the game and the map editor need to draw the map on the screen (almost) the same way, so there is no sense in writing that part of the code more than once. You should make your architecture so that those parts are decoupled from the game logic, in order for you to separate them into their own modules.

The map editor does not need to be bundled together with the game. It might be easier to have them both as separate programs. You just need to put the common code into separate JAR archives, so that you can include those JARs in both the game and the editor.

Jackal von ORF explained it pretty well.

The “engine” of the game is basically just the code, assuming that your data is stored in files of some kind rather than in the code. The engine of a car is what makes a car go, so the engine of the game is what makes a game “go”. The reason people talk about it separately is that it is sometimes possible to use the same code to make multiple games just be changing the data. In fact, writing your code in that way is usually preferred.

Sometimes you can license a game engine that’s premade and just modify it slightly (or even not modify it at all).

A while ago, I made an RPG with a map editor. They both displayed the same maps in the same way and just had some different buttons and so forth. Since the screen scrolled with the mouse in the game, I just reused that code in the map editor as well instead of adding a scroll pane or something.

The main difference was that the actual game had a loop or something for moving the characters, combat, etc, where the map editor just had the ability to edit the objects.

Thanks guys for the great examples, I guess i am/was a bit confused because I dont think I write my games like that. For example. I have a map class that has the 2D array and the other methods the map needs. I am going to make it so my map class reads the data for the 2D array from a txt file. so therefore i would be able to use that Map class for the MapEditor and the game right? Since the map editor could use the map class to read and write to the txt file and store info about the map?

Once again I really appreciate the advice:)

Yes, you can use the same Map class for both. It’s the same file either way, so it might as well be read and written by the same class.