Render a procedurally generated world into a sprite or tilemap

Hi, I need to implement a map system into my procedurally generated world. I have four variables to determine where items and biomes go: elevation, temperature, humidity, and scatter (for vegetation), and I use a Perlin Noise function to create the infinite world, and a random seed.

What I want to do:
I want to be able to render a section of the procedurally generated world (that is not yet generated or visible) onto one sprite, with each variable determining the color of the pixel of the sprite so it shows up as a map. Doing it on a tilemap would be good too. This is fairly advanced and complicated stuff, so I kind of need help with it!
This will be used in a UI map system that the player can view to see where on the generated map he will be.
Conclusion.
If someone would be able to solve this complicated coding problem I would be very grateful. You would kind of need some experience in procedurally generated worlds to do this, like making games like 2D minecraft or cubic world or minecraft or terraria.

Anyone has any help?

Mate, it’s less than a day since your initial post and you’re bumping it already? Not everyone’s online or ready to jump to your assistance.


The first thought that comes to mind is to render each pixel of a sprite with the 4 variables assigned to the RGBA value of the pixel. However, I’m not aware of an extension to write to pixels and my understanding is that this isn’t possible with the rendering engine. I’d be happy to be proven wrong.

So, I think the best alternative solution is to have a separate layer in the scene, and use a ShapePainter object to draw each pixel (or block of pixels) onto that layer. Then add the Object Masking extension to display part of the layer.

However, you may want to put the alpha value in a range from 128-355 otherwise this would render whatever pixels have a vary low alpha value as nearly transparent.

If this is not what you’re after, then you’re going to have to give more specific details.

Hi Mr Men, thanks for the reply, it is very helpful! Thanks for taking the time to answer. I will check out the shape painter and see if I can do anything with that, maybe it will work.

what about that one extension that can render the viewport to sprites?

oh…im sorry, i see what you mean now. why dont you use another tilemap thats just smaller and then map it to that?

Yes ok I will try to do that. How will I map the coordinates of a scene onto a grid of a tilemap? Like I want to convert You.X(), You.Y()'s boundaries by around 1000 pixels onto a 64x64 grid of a tilemap.

This is not advanced and i am surprised you were able to get procedural generation with perlin noise
Yet you struggle to do map

Think of it like this
IF you create your world by values from perlin noise
How you ever you set object to be stone or tree or grass or whatever
Now you need to do the same to however you make your map

For example if you create stone if perlin noise value = 3
Then in same place of shape painter you draw gray object
Or change tile on tilemap to be gray

That’s it
You just need to test it on small area
And you could render HUGE chunk of map this way but render only part of it
For sure you should not do it each frame

I would go with tilemap object cause its most efficient
OR maybe mix of tilemap and sp?
That depends do you wanna add moving objects to it

I’m curious how you’d set the pixels on a tilemap object. Can either of you give an example of it working on a randomly generated scene?

NOT pixels but tiles
Maybe you confuse idea of it with what was OP trying to achieve
Look i made auto tile out of tilemap

Wherever i place (LMB) tile or remove (RMB) it
I check adjacent tiles by assigning number to wherever center tile is
Like 010 where that 1 there means center tile
And so
Green Blue and Yellow are center tiles
Where Red are adjacent


So if you look on image on the left
And we have one tile top left from center one
And 2 tiles on right where one is directly right from center one and other one bottom right from center one it will generate number 106
And then i can map it with whatever tile should be in that scenario thx to image on the right

One left from center and another one bottom left from center = 600
In below center one = 040
One in top right from center and one on bottom from center = 005
600 + 040 + 005 = 645
Which would be tile with ID 17


Same exact logic would go to creating map out of procedural generated map
SINCE its using perlin noise it means at position SOMETHING value of what should be there will always be the same with some seed

So we could have tilemap with few tiles like even colored squares
And so since we know there would need to be grass we would put there tile that is gray square

Now we would either do it with having tilemap on different layer
And we could change zoom on that layer to fake map being bigger or smaller

Or we could simply do math to move tilemap object to SOMEWHERE
And render only part of our world into tilemap object

I failed trying to get noise generator to work that is why its bizarre to me that OP was able to get it to work but not make map out of it

So i am unable to show how both things would work
BUT i could totally go with random in range to just place for example grass/trees on my scene and make map out of it with tilemap object
If you want?

Logic for detecting tiles for autotile

For map it would be easier cause you don’t detect anything you just set tile to something based on value of that position

Sorry mate, that’s quite wordy and it has a difficult flow to it. From what I gather is that you’re describing 8-way tile bitmasking. And I understand that fully - I was using it 30 years ago, not to mention a GDevelop solution I made with it a while back.


I don’t think so, unless OP has changed their mind and decided that adjacent cells/blocks affect each other. Which is not something they mentioned in their initial post.

And sure, you could place objects on a layer and zoom out. That’s a viable option, but could prove tricky - that zoom would have to be 100% accurate (not 99%) so each object is exactly the size of a pixel. Any thing slightly smaller or larger and you’ll get single objects covering 2 pixels or objects being left out.

NO NO NO
You totally missed my point
Or i did not explain it well enough

I was proving that you can use tilemap object as a map
To set individual tiles to something as you please based on some value

For autotile it works for adjacent tiles

For map of your well “ground/map” it would be same exact logic for setting tiles to something just without checking for adjacent tiles

I get out of your previous message you were unaware how to do it using tilemap so i did give you example how to do it with tilemap for something similar

But i guess that proves nothing for you
So let me make example for you with random in range generated terrain cause like i said i never was able to get noise generator to work

Just give me some time

And if I understood you correctly, you add tiles to the tilemap and then zoom out to make it a mini-map.


However, depending on what values the variable can contain, have you taken into consideration the number of objects required?

I’ve gone for the following:

  • Elevation is probably a number between 0 & 255.
  • Humidity ranges from 0 to 100.
  • Temperature, say from -40 to 40 Celsius.
  • And then there’s scatter say that 0 to 10.

That means there are 256 * 100 * 80 * 10, or over 20 million unique combinations of these variables. How would you represent that with a tilemap?

I don’t add them to tilemap i change them on tilemap
So on one tile space there will be one tile i just would change its ID

BUUUUUT
I need to say i stand corrected now i get what you did not understand from my idea
Since i did not understand full scope of the idea
I totally missed part with temperature and height
So my initial idea was to just have tile represent object from top view
If there would be stone at Z 10 or Z 200 they would look the same

TECHNICALLY i can totally take take color palette like

And use that as tilemap
And have few tilemaps on top of each other
with semi transparent atlas to fake whatever i want
I would need something closer to

And that would be totally doable

Anyway to clarify
I was sure issue we are talking about is how to use tilemap to make map out of terrain

But now i get what we are talking about is that + how to make each represented object on map have some attributes like elevation and temperature and humidity
STILL totally doable with what i had in mind
But way more complex due amount of tiles on tilemap you would need to 1st map (like give them purpose based on values)

So yeah i can totally see why what i wrote confused you
Seems like rendering it with something like SP would make way more sense since now you could use color conversation extension to convert RGB to HSLA
And now you could just do it via pure math
But even after that conversion if you would have proper formatted tilemap atlas you still could do it with just math

Again i stand corrected however i am still pointing out with tilemap it would be 100% doable after that RGB to HSLA conversion

I guess i won’t be able to make proper example to account for all that is asked by OP

For example this alone would work for water


Now i would need one for green stuff like grass and trees (they could share same atlas) and something for stone

And i could totally slap tilemap onto tilemap to get desired effect
But AGAIN would not be fast to prepare and rendering simply to SP would make a lot more sense

Hi, thanks for all the advice, I am currently working on a tilemap that can display colors based on a procedurally generated map, figuring it out!

i mean, i now know what the op meant. yes i did mean use the tiles not the pixels, but now knowing that the tiles wont work because the color needs to be dynamic, @Crowbar_Coder you could try using just sprites in a grid, if you do it like that at least you can tint them right?

Tiny square sprites, say 1x1 or 2x2 pixels in size? Include the Object Masking and you have yourself another candidate solution.

whatever scale he wants. but i warn against 64x64, its small. try 100 with a “tile” size of 5.

also you dont need a mask. a square map could look really cool, or you can make the edges look like paper

masks are absolutely lethal on performance

So you’d recommend updating the minimap on the fly? I’m more in favour of using a Shape Painter object on a layer with the use of a single object mask. It’d be interesting to see which is the more optimally performant.