Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 4586 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Member





« Posted 2008-02-24 03: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 Member




shiny.


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

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

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 Member





« Reply #2 - Posted 2008-02-24 19: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.

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

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


Best wishes,
Keith

Offline Swattkidd7

Junior Member





« Reply #4 - Posted 2008-02-25 04: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 Member





« Reply #5 - Posted 2008-02-25 05: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 Member





« Reply #6 - Posted 2008-02-25 07: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 Member





« Reply #7 - Posted 2008-02-25 11: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 Member





« Reply #8 - Posted 2008-02-25 20: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 Member





« Reply #9 - Posted 2008-02-26 00: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 Member





« Reply #10 - Posted 2008-02-26 12: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!