Best Way To Do Mini-Map?

Hello Everyone,

I would like to add a mini-map to my game but i just don’t know what is a good way of doing one, I had an idea where i would draw my tilemap twice and the second one a little smaller. Does anyone know any good ways of making one ?

-GlennBrann

If the minimap will show that much information, why not just let the player control the camera zoom? If it is a top down game, you can give each tile one pixel and use simple coloring like grass = green, lava = red, water = blue. Or, if it is a side view game, color solid ground black and give enemies/power-ups/save-points different bright colors.

I would just draw your map a second time but only with simple colors (maybe not even textures). Depending on what time of game youre making, you may or may not need to update the tiles in your mini map. I would also render entities as simple small colored dots. The rendering should be fairly easy I think actually optimizing it would be hard though.

Ok well i created a new class called MiniMap and i basically load the same text file that the map is stored in and i set each tile to 1 pixel. Is this a good way of doing it ? How would i check where the player is on the map ?

Well, first off I would make it a tiny bit bigger, maybe 2x2 pixels and your regular game tiles should have world coords, just divide each tile in your world to have the coords be the same as your minimal coords. Since that makes no sense at all, I’ll try to do some math!

Say your regular tiles are 16x16.
Minimal tiles are 2x2.
Your player in the world is at (16,16) or the tile diagonal from your world origin.
To render that on your minimap you need to simply take 16 and divide it by your minimap tile size. So 16/4 which equals 4. So you render your player at position (4, 4) on your minimap.

Just say if that didn’t make sense!

Ok i get what you mean, But maybe you could help me again, My regular tilemap as x and y cordinants. and my minimap has its own cordinants. Lets say i want to render a white square at the tile on my mini map where my player is. how could i do this. using your method

This is how i render

g.fillRect(miniMap.getX() + 32 / 4, miniMap.getY() + 32 / 4, 2, 2,)

the 32 is the size of my regular tiles. I’m not to sure if i should be putting in the x & y for my player or the x & y for my regular tilemap. could you help. Thanks

  • GLennBrann

You should be using your player coordinates. So, for instace:

g.fillRect(player.getX() * minimapTileSize, player.getY() * minimapTileSize, 2, 2);

This code should be in your minimap render method. Its simply saying get the x and y of the player and multiply them by the tile size of the minimap.
Again, some more math:
Player position in pixels (2, 3)
Player position in world coordinates (2 * 32 = 64, 3 * 32 = 96)
Player position in miniMap coordinates (64 / 4 = 16, 96 / 4 = 24)

Hey man, Thanks so much for the help, I now know how to do basic enough mini maps.

I used this code to get it to work for the player. I used what you did but tweaked it to my code a little.

g.fillRect(x + player.getX() / 32 * 2 , y + player.getY() / 32 * 2, 2, 2);

Thanks alot

  • GlennBrann

Glad I could help! But, can I ask what the y and x variables are that you’re adding to the player x and y? Are they offset variables or something for the tiles?

Yes they are the x and y variables of the minimaps tiles offsets. if i don’t want the hole map rendered in the map. i can scroll through the map

Ah, I see. Just wondering!
Good luck with the rest of your game!