Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (653)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Creating a 2D Tile Map editor  (Read 5794 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Posted 2008-02-24 02:13:54 »

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).

Offline Mr_Light

Senior Devvie

Medals: 1


« Reply #1 - Posted 2008-02-24 11:16:07 »

just wrap the JPanel in a JScrollpane.     

add(new JScrollpane(panel));

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #2 - Posted 2008-02-24 18:24:40 »

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CommanderKeith
« Reply #3 - Posted 2008-02-25 02:24:44 »


You should check out this tile map editor:

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

Best wishes,

Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #4 - Posted 2008-02-25 03:40:10 »

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:)
Offline fletchergames

Senior Devvie

« Reply #5 - Posted 2008-02-25 04:14:41 »

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.
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #6 - Posted 2008-02-25 06:27:48 »

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 Undecided....

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).
Offline Jackal von ÖRF

Junior Devvie

« Reply #7 - Posted 2008-02-25 10:18:28 »

Like what classes would the map editor and the game loop have in common that they both  use?

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.

Offline fletchergames

Senior Devvie

« Reply #8 - Posted 2008-02-25 19:46:49 »

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.
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #9 - Posted 2008-02-25 23:41:57 »

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:)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fletchergames

Senior Devvie

« Reply #10 - Posted 2008-02-26 11:38:52 »

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.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

SHC (26 views)
2015-08-01 03:58:20

Jesse (19 views)
2015-07-29 04:35:27

Riven (40 views)
2015-07-27 16:38:00

Riven (21 views)
2015-07-27 15:35:20

Riven (24 views)
2015-07-27 12:26:13

Riven (14 views)
2015-07-27 12:23:39

BurntPizza (36 views)
2015-07-25 00:14:37

BurntPizza (46 views)
2015-07-24 22:06:39

BurntPizza (30 views)
2015-07-24 06:06:53

NoxInc (37 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!