- Home /
How to make a minimap by pixels without second camera
I'm doing a procedural, grid based game, and want to make my minimap by allocating each grid coordinate a colour. Then having the minimap show 1 pixel per grid coordinate.
The only game I can think of that does something similar is Tibia
In the above picture, each square is one pixel and represents one tile on the map. All the different grass is just "Green" and trees are "Dark green". Roads / Dirt / stone are grey or dark grey. This then gets used as the minimap "texture".
It's also only discovered in a rectangle around the player (hence the ocean turning black) but that's optional and relatively easy.
I can't find any resources to work in this way.
How can I do this? The only thing I can work out so far is to have a C# section of code that uses image libraries to draw a PNG or other indexed image and load that image in as the map in x * y sized chunks. The actual world itself is procedural, so can't be known ahead of time.
Edit: More detail on question
How can I turn an array of values (or list, or any collection) such as
20002002
21112002
20002002
11111111
Into an image or texture that I can draw as 4x8 rectangle of pixels? (Or use as a texture for a poly?
I do something similar. Procedurally generated tiles and a $$anonymous$$imap, but I do use another camera for UI purposes.
You said you dont want a second camera so it depends on how you are going to display this map. Built into the UI? It also depends how your world is generated. Is the entire world generated at the start or is it generated tile by tile as the player travels?
The world I create in my project is all generated at the start. $$anonymous$$y $$anonymous$$imap reveals the tiles if the player steps on them.
The way I achieve this is:
-Each of my tiles have a "type" (Grasslands, forest, etc). This is helpful for the $$anonymous$$imap tile to know what it should display as its material. Grass = green, Forest = dark green, etc. This also allows me to create a single $$anonymous$$imap tile prefab and reuse it over and over, changing its "type"
-Each of my game world tiles are the same size (50x50)
-For each of the tiles I create a UI representation of that tile. In your case if you want solid colors, create a plane and put a green texture on it or however you want to display that tile.
-All the game world tiles are added to a list OnLevelLoad
-Since all my tiles are the same size (50x50) i can take that info and setup my $$anonymous$$imap tiles as a "duplicate". If i want a map that is 1/10th the size its just 50 * .1
-All of the tiles are then replaced with a "black" or "see through" material to signify they havent been explored.
-When the player explores a gameworld tile, that tile activates a Reveal(); function and changes the corresponding $$anonymous$$imap tile to its original material.
$$anonymous$$aybe not exactly what you asked, but its the way I have achieved a $$anonymous$$imap in a procedural tile-based world.
That sounds close, but on a much larger scale. I want one:one relationship between pixel on $$anonymous$$imap = a 32x32 pixel tile.
If you want a pixel per tile I would think you would want to create a new texture with the scale being your entire world.
Treat each tile like a pixel.
if you have a 50x50 tiled world (with each tile 32x32), you would have a 50x50 texture size. tile at position x: 64, y: 96 (or x:64, z:96 if your world is flat inside unity and is 3d) would be easy to get the pixel position. Just divide by the tile size, 32. set the pixel at 2,3 to the color of the tile you want revealed
I have never done this before, just a theory.
you may want to take a look at
http://docs.unity3d.com/ScriptReference/Texture2D.GetPixel.html
http://docs.unity3d.com/ScriptReference/Texture2D.SetPixels.html
http://docs.unity3d.com/ScriptReference/Texture2D.SetPixel.html
Those links look promising.
I'm a little concerned with how much of a performance hit it might cause, as it mentions in the link, but I only need to call it once per hundreds or even thousands of frames.
Answer by alebasco · Aug 21, 2014 at 05:39 AM
Creating the image once you have the data can be done via many different tutorials - but getting the proper data will be the hard part.
I see a couple of options -
Raycast down at every grid position. This will be expensive, and you'll have to either do it all at once when the game loads (and put up a loading screen or something), or do it over time, while the player is moving around, doing a few raycasts per frame. Depending on performance of your game / how fast you move / how big your grid size is, this maay work.
Have each object report its location, and type to a manager. This will only work if you have grid/voxel based objects, but would be much easier. Since you mentioned creating the world procedurally, you might already have some load time and could do this as you create each object, report the type and grid position to a manager.
$$anonymous$$y problem isn't getting the data (I can easily get whether the "top" tile is grass, dirt, tree).
$$anonymous$$y problem is how do I turn
0011011010
0101101110
0111010101
Into a 3 x 15 rectangle of pixels that I can draw in Unity.
@shadbags, I don't know exactly how to do it, but it should be possible with .NET, check this namespace: http://msdn.microsoft.com/library/system.drawing(v=vs.110).aspx
So I use C# native drawing to draw the bitmap, save it, and load it as the material for a poly drawn as part of the UI?
Your answer
Follow this Question
Related Questions
Suggestions about creating a big map 1 Answer
Assigning UV Map to model at runtime 0 Answers
Can I make an open world with this engine? 1 Answer
Drawing an overlay mini-map 6 Answers
Terrain normal map. 1 Answer