Custom Tile/Level Editor in Java

So I’m planning on making a tile-based survival game in LWJGL. (Yep I’ve finally been converted to pure LWJGL I guess I’m kicking Slick2D to the curb) Right now the game runs off of maps that are arrays of numbers:


int[][] map = {
				{1,1,2,2,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{1,1,2,2,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{1,1,1,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
		};

I want to make a custom level editor so I don’t have to do all this number crap. Any technique I can use?

I would need a program that could load images into it and make those arrays. Or should I use a program that is especially made for my game, something that already has all the tiles I need in it? I don’t know. I just need a little counsel on this before I blow into a huge editor and break something.

You could import an image which is translated to a two dimensional array.
Where color Z is translated into 1, color X into 0 and Y into 2.

You dont need a program that do the conversion, it could be done in a single method.

public static int[][] encode(String imagePath)
{
         //.... Code
}

I have done similar for my game.

Also, to save RAM, you should use byte array instead of int array.

The editor is essentially a GUI around a few simple functions:


tileIDs -> tileMap
tileIDs + tileImages -> tileSet
tileID + tileSet -> tileImage (for the display)
tileMap + tileSet -> file

Add the reverse of a few of those, a way to display and manipulate the underlying collection, and you have an editor.

So whats wrong with Tiled?

LibGDX can even render Tiled maps.

If you’ve got to the point where you can display a tile map in your game, start making an ‘edit mode’ inside your game. have a currentlySelectedTile, when ever the mouse is clicked, change the grid space to that tile. use +/- keys to change which tile youre drawing with. F1 to save, F2 to load. Thats enough functionality to get quite a lot of mapping done, and you can expand and alter it as you need to.

Should be a buffered image, for polymorphism. And you could automatically generate noise for a random level generator. (OpenSimplexNoise here: https://gist.github.com/KdotJPG/b1270127455a94ac5d19)

Also, to load a javaIO File -> buffered image is [icode]ImageIO.read(…file);[/icode]

What does this even mean?

If anything it should be a 1D array or Byte/Int/X Buffer :point:

Sure, store as a image file for convenience, but as soon as you load in the image grab the data buffer and use that.

I just mean you shouldn’t load the image using a string, or even a file really. So you can generate a buffered image elsewere and still make a map out of it. I wasn’t talking about the return type, sorry for the confusion. xD

Ts’all good.

Nowadays I just have almost anything not performance-critical as Streams. So convenient and easy to read.