Current strategy for creating my procedural mini map is performance taxing
Basically, I'm procedurally generating a top down game using perlin noise. The actual world is filled out with 16x16 tiles, and my strategy for generating a minimap has been to basically generate the same world but at a smaller scale. The issue with this is that it results with the UI canvas generating thousands of 2x2 pixel sprites and really bogs down the game. Looking for alternative solutions, maybe some way of rendering the map as a single image using the data from world generator?
public BiomePreset[] biomes;
public GameObject tilePrefab;
BiomePreset biomeToReturn;
[Header("Dimensions")]
public static int width = 50;
public static int height = 50;
public static float scale = 1.0f;
public Vector2 offset;
[Header("Height Map")]
public Wave[] heightWaves = new Wave[2];
public float[,] heightMap;
[Header("Moisture Map")]
public Wave[] moistureWaves = new Wave[1];
private float[,] moistureMap;
[Header("Heat Map")]
public Wave[] heatWaves = new Wave[2];
private float[,] heatMap;
[Header("UI Stuff")]
public GameObject mapPrefab;
public GameObject mapBorder;
public Canvas can;
public static float scaleFactor = 2;
private void Awake()
{
//rt = mapPanel.GetComponent<RectTransform>();
GenerateWaves();
GenerateMap();
}
void GenerateMap()
{
//height map
heightMap = NoiseGenerator.Generate(width, height, scale, heatWaves, offset);
//moisture map
moistureMap = NoiseGenerator.Generate(width, height, scale, moistureWaves, offset);
//heat map
heatMap = NoiseGenerator.Generate(width, height, scale, heatWaves, offset);
GameObject m = Instantiate(mapBorder, new Vector3(-960 + width, -540 + height, 0), Quaternion.identity);//creates the gameobject which holds the map
m.transform.SetParent(can.transform, false);//sets the mapholder as a child of the UI canvas
RectTransform rt = m.GetComponent<RectTransform>();//gets the recttransform of the map holder
for(int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
GameObject tile = Instantiate(tilePrefab, new Vector3(x, y, 2), Quaternion.identity, transform);//generates the tile
tile.GetComponent<SpriteRenderer>().sprite = GetBiome(heightMap[x, y], moistureMap[x, y], heatMap[x, y]).GetTileSprite();//sets the tile to the correct sprite
tile.GetComponent<TilePrefab>().biome = GetBiome(heightMap[x, y], moistureMap[x, y], heatMap[x, y]);//sets the biome of the tile
GameObject dot = Instantiate(mapPrefab, new Vector3((x * 2) , (y * 2), 0), Quaternion.identity, rt); //generates the minimap tile
dot.GetComponent<Image>().sprite = GetBiome(heightMap[x, y], moistureMap[x, y], heatMap[x, y]).GetMapSprite(); //sets the minimap tile to correct sprite
}
}
rt.localScale = new Vector3(scaleFactor, scaleFactor, 1);//scales the map(larger world map will still have same size as smaller world map)
rt.position = new Vector3(1920 - (width * scaleFactor), 1080 - (height * scaleFactor), 0);//puts the map in the top right corner
}`
Theres more to the script but its not important to the question.
Your answer
Follow this Question
Related Questions
How to check if a 2D object is ahead of the player? 1 Answer
2D Top down projectile help (not moving) 0 Answers
Changing player position when changing scene 1 Answer
Rotating weapon in top-down 2D 0 Answers
zelda/issac like mini map 0 Answers