I have this system for a game, in which I have two channels on each pixel of a png/“tilemap”. The Program reads these values, and places tiles based on Blue, and objects based on red. I.e, 1 red and 1 blue would be a player on a dirt tile. I want to know how to be more organized here. What I mean, is I need tile editing software. Something that will let me see, not the pixels, but the tiles. Any tile softwares that use rgb? Google searches have been inconclusive.
which one are you trying to get ?
What do you mean by RGB system? Everything uses RGB…
i have no idea about what you are talking about ,
RGB = Red Green Blue, this is how digital colors are made
dude you’re really confusing us, is there a change that you have a file,array or string that is fulled with something like this
and that’s mean that you’re player is in the middle of a dirt tiled map ?
That’s a really, really confusing system. No offense, but I really don’t think it’s the right way to go about things. Just use the standard system - each number/letter represents a different entity/thing. So much simpler to implement and understand (and debug, I imagine).
Does Paint/gimp not suffice?
If not, why not make your own tile map editor?
am with Jimmt here, what you are doing will really cause you a lot of trouble later, it’s like that your goal is right in front of you, but you decide to go take a loooong walk and come back to get it, so just like Jimmt said, working with a standard tile system will fix the “problem”
[quote]I use paint.net, and I can use it, but it gets confusing telling 1 notch of red from no red. I need something where I can see the tiles.
[/quote]
you’ll simply need to create a grid, i think there is a plugin for Paint.NET to do that, or just draw your grid inside your java game, take that image (screen shot) and use it as a background in your paint program
i can say yes, because in you case you are implementing the player in the tile,
i never saw any tiled system (never think about it either) to have the player value inside the tile
guys do you agree with that ??
are you talking about there starting position or during the game ?
if the starting position, then you’ll just need to set it up in the beginning of your game (the Create() method in LibGdx)
if during the game,then get their X and Y and just find them
PS :
can i know what is the type of the game you’re making ?
alright, so generally how a tiled map work :
1-you define the size of your tile
2-you define the size of each tile block
3-you draw the tile depending on external information (generally a text file)
so let’s say you have an 8x8 tile map, and the block size is 32pixels
and you have a text file like this :
in order to draw your map, you should
-iterate inside your text file
-check what is the value of the current character (0 or 1)
-then to draw your block (i think that’s what you call pixel) you need 3 values :
-pos :the X & Y position of the current character
-val :the value of the current character
-size :the size of each tile
then you draw a graphic with the type “val” in the position “pos” multiplied by size
i used that in this project if you download it, you’ll see that am not only able to load a tile map from a text file, but also i can create a new tile map inside the game which is very useful, and therefor you will not need any program to create your game world
good luck
if you want to make a map out of an image, just go through each pixel and check its rgb. Map an entity or something to a certain rgb, and if that rgb appears, spawn it in that corresponding position.
So your setup is that the red channel shows tiles, and the blue shows entities? For example:
You change the red value, and you change the tile.
Having red as 0 may equal dirt, whilst 1 may equal grass, etc.
Change the blue value, you change the entity.
Having blue as 0 may equal no entity, 1 as player, 2 as zombie, etc.
You can easily modify tiles through paint, through edit colours -> and then change the Red, Green and Blue values there.
It’s the simplest way of doing what you wish to do.
To enable a grid in Paint.NET: View->Pixel Grid
@Using different channels meaning two/three types can exist: I tried this, and it is ugly. Say the level is 16x16. Make the image 32x16, and when loading, split it into two 16x16 images, and read each type off that.
@Telling the difference between 0 red and 1 red etc.: Just change the colour that maps to each tile. ie: Make the player spawn at 16 red or something.
Here’s a sample map from Guardian II: (Yeah, it’s small)
See how there is a significant difference between all the kinds of tile?
Also note that it’s only one set of data. All other data such as spawn points are defined in a .txt file that is parsed during loading.
What the heck are you doing? It was the right suggestion, use Tiled.
With your RGB image you have 3 channels: Red, Green and Blue, but with Tiled you simply create different layers (as much as you want to). Also, you can see the immediate result, instead of simply colors. The tiles show instantly.
LibGDX has a Tiled map reader,
and there are many more tiled map readers out there for java.
I think his problem with using [the approach where color X = a tile, color Y = an entity instead of using different channels] is that, as his game is top-down, he cannot know what the tile below the player is. It’s fine when making a platformer as you can pretty much always assume that it’s air. However, with a top-down perspective he’d have to create a system in which he can, from the number given, assume the tile below.
By using different channels he can differentiate between tile and entity alike. However, his solution to the problem may not have been the best, as either the player will not be loading precisely where they left off(he would have to round the player location to the nearest tile), or movement will not be smooth between tiles(as the player would always be locked to a tile), which is not optimal in a top-down game.
@wesley.laferriere, it may be best to listen to what people are saying and use a Tiled map instead of an image, and use a .txt or w/e to store all the entities and all their states:
//entity pos health
player 0,0,0 100%
zombie 1,4,4 1%
//etc.
Why not just build a simple map editor and export it into a txt file for your game to read? Like mine =P
Or use TileD as others suggested…
To explain it to all the dummys who dont understand what he means by RGB map
we wants to make an image file: bmp, png what have you in software like photoshop and then read that to generate a map from it by reading the color of each pixel.
its not crazy it has been done, it buys you that you have a map editor already…
I personally dont recommend it, but it can be done
I just glossed over a few posts before replying here but what you want to do is almost exactly the way that I’m loading my map. The way I have it set up will probably be a bit stupid to other people but here goes…
The first thing I do in my ResourceHandler class is to load the map-image and get the values for each and every pixel on the image. Below is a CnP of the code I use with a lot of it edited out, it’s just to give you a basic idea:
public void loadImages()
{
currentMap = loadMap("Resources/Maps/Maps/TestMap.png");
}
//Load Map
private int[][] loadMap(final String x) //Requires the map's file name. Don't include the extension.
{
try
{
final URL url = this.getClass().getClassLoader().getResource(x);
final BufferedImage bufferedImage = ImageIO.read(url);
final int mapWidth = bufferedImage.getWidth();
final int mapHeight = bufferedImage.getHeight();
final int[] pixels = new int[mapWidth * mapHeight];
int[][] map;
bufferedImage.getRGB(0, 0, mapWidth, mapHeight, pixels, 0, mapWidth);
map = new int[mapWidth][mapHeight];
for(int row = 0; row < mapHeight; row++)
{
for(int column = 0; column < mapWidth; column++)
{
//This statement slows everything down, only use it to find the value of a pixel. System.out.println(pixels[row * mapWidth + column]);
map[column][row] = pixels[row * mapWidth + column];
}
}
return map;
} catch (IOException ex)
{
ex.printStackTrace();
}
//This should never be reached; from all the tests so-far it has never been reached so it can be assumed that it never will be unless under some unforseeable circumstance.
return null;
}
The next thing that I do is to use the code below in the rendering part of the game loop to draw the map to the screen.
//Render Map
for(int row = mapWhatToDraw[0]; row < mapWhatToDraw[2]; row++)
{
for(int column = mapWhatToDraw[1]; column < mapWhatToDraw[3]; column++)
{
switch(currentMap[column][row]) //Note: To increase the player's walking speed just times both the playerXPosition and playerYPosition by a speed multiplyer
{
case -1237980: //Grass
{
g.drawImage(resource.getSprite(2, 0, 0), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -3584: //Grass Flower 1
{
g.drawImage(resource.getSprite(2, 0, 1), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -16735512: //Grass Flower 2
{
g.drawImage(resource.getSprite(2, 0, 2), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14503604: //Stone Path
{
g.drawImage(resource.getSprite(2, 0, 3), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14503860: //Stone Path
{
g.drawImage(resource.getSprite(2, 0, 4), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14504116: //Grass-Stone Path_1
{
g.drawImage(resource.getSprite(2, 0, 5), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14504372: //Grass-Stone Path_2
{
g.drawImage(resource.getSprite(2, 0, 6), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14504628: //Grass-Stone Path_3
{
g.drawImage(resource.getSprite(2, 0, 7), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14504884: //Grass-Stone Path_4
{
g.drawImage(resource.getSprite(2, 0, 8), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14505140: //Grass-Stone Path_5
{
g.drawImage(resource.getSprite(2, 0, 9), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14505396: //Grass-Stone Path_6
{
g.drawImage(resource.getSprite(2, 0, 10), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
case -14505652: //Grass-Stone Path_7
{
g.drawImage(resource.getSprite(2, 0, 11), column*40 - playerXLocation, row * 40 - playerYLocation, null);
break;
}
}
Now you’re definitely wondering what the heck all of those random numbers that mean absolutely nothing, as far as I know, mean. Well, as far as I know, they’re just some nonsense given to you if you do “System.out.println(bufferedImage.getRGB(0, 0, mapWidth, mapHeight, pixels, 0, mapWidth));” up in the map-image loading code. It’ll give you a unique number for every single color and that’s the number that you use in the case statement above to decide which tile to draw. This way of loading the map can be a pain in the butt if you forget what to do but it works very well for me and that’s why I use it. ^.^