Public Group

# Bitmaps for tilemaps

This topic is 1679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello i want to know a tutorial about this topic "I don't know how work this to create the map and to know the character position using this super pixeled map":

How is that called?

Other question..

In this demo, if we go to bob.java

we find:


int p1x = (int)bounds.x;
int p1y = (int)Math.floor(bounds.y);
int p2x = (int)(bounds.x + bounds.width);
int p2y = (int)Math.floor(bounds.y);
int p3x = (int)(bounds.x + bounds.width);
int p3y = (int)(bounds.y + bounds.height);
int p4x = (int)bounds.x;
int p4y = (int)(bounds.y + bounds.height);

int[][] tiles = map.tiles;
int tile1 = tiles[p1x][map.tiles[0].length - 1 - p1y];
int tile2 = tiles[p2x][map.tiles[0].length - 1 - p2y];
int tile3 = tiles[p3x][map.tiles[0].length - 1 - p3y];
int tile4 = tiles[p4x][map.tiles[0].length - 1 - p4y];


I mean is using the position of the bound to take the tiles ,, but it doesn't makes sense to me to do tiles[p1x][whatever2] . Can someone try to explain me?

Thanks!
Ventura

##### Share on other sites
'tiles' is a two-dimensional array. You are getting the int at the location tiles[x][y] in the 2D array.
This code isn't very cleanly written.

What appears to be occurring is that the player, who has a rectangle collision box, can overlap (be standing on) up to four tiles at once. So the code is getting those four tiles (which might be all the same tile, or two separate tiles, or four separate tiles, depending on where the player is standing).
(p1x, p1y) is one corner of the player's collision rect, (p2x, p2y) is another corner, and so on.

tiles[] is the tile layout of the map, and each int is a tile index used to look up the tile details in the map (specifically, whether the tile is deadly to walk on or not).

'tile1','tile2', etc... are the four IDs (or possibly map indices, I don't see the 'Map' class' source code) of the tiles.

For your first question, how to turn an image into a map, you do this:
B) Iterate over each pixel of the image
C) If the color of the pixel is (0,0,0,0) you make your map have one kind of a tile. If it is (255,0,0,0) you use a different type of tile.

##### Share on other sites

oh I got the answer of the second, this is because use a custom world coordinates instead of a screen pixel coordinate

##### Share on other sites

thanks for the answer crossbones, I inderstand now much better :), good answer. The second one is because libgdx allow world coordinates, not only pixel so you can draw in your world coordinate and it will be transformed to the user resolution automatically. Something like that I understood..

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013630
×