I am trying to develop a randomly generating “maze” for my upcoming game. Problem is, if i surpass the 500/600 objects mark with walls - the game starts to experience exponential lag.
These walls are currently just stretched 100x100 sprites but in the future I also want to make every wall separate to:
- make them not stretch
- have them differ depending on if they are corner, center, edge walls etc.
I have found 2 solutions to help that:
One is to simply delete the walls that are very far away and constantly generate new ones if required - this drops down the objects significantly, to around 200 with high density. The problem with this approach is that the maze is being constantly re-generated.
The other way I found was to split the spawner into smaller ones, I also used this method for the first solution. This way I could spread out the walls more evenly, thus decreasing the amount of walls required. This helps - it drops the object count from 900-1000 to 500-600, which still produces noticeable lag but not as much.
Is there another way of optimizing this or will I need to resort to splitting the spawners to smaller ones to distribute the walls better?
Also, I want there to be tight and open sections, so I cannot just decrease the amount of walls. I could try to optimize it in a way where chunks are split into open and closed ones though.
EDIT: (the map is 16000x16000) I just tested the spawner splitting, the spawners were 4000x4000 before, now they are 2000x2000. I could decrease the amount of walls per spawner ever so slightly - now there are around 400 walls but the density on average is noticeably smaller.