Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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?

Share this post

Link to post
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:
A) Load the image
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 this post

Link to post
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..

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!