I also found that corona has already a Perlin Noise generation and can be used to create tile maps as well
What are you referring to?
The problem is that the Perlin Noise generation in corona is not an actual generator, because it gives the same result every time.
This is by design. Noise algorithms, in the computer graphics sense, produce coherent randomness: if you compare the values yielded by some pixel and any of its neighbors, they will be close. (As opposed to white noise, where the values are all over the place.) Generally this will mean the values themselves must be fixed.
What you want to be doing is sending unique inputs to the algorithm for each tile, say the row and column. If your concern is then that you always get the same map, you just have to offset these (this is basically like seeding a random number generator), probably with some wide step so you don’t land near the values from your previous map. Something like:
function CreateLevel (cols, rows) local col\_offset = math.random(-150000, 150000) -- spread the numbers out a bit local row\_offset = math.random(-150000, 150000) for row = 1, rows do for col = 1, cols do local sample = PerlinNoise(col + col\_offset, row + row\_offset) DoSomethingWithIt(sample) end end end
If you do want to treat it like a generator, you could just maintain a counter and march in one direction:
local Index = 0 function CreateLevel (cols, rows) for row = 1, rows do for col = 1, cols do local sample = PerlinNoise(Index, 1) -- assuming 2D noise DoSomethingWithIt(sample) Index = Index + 1 end end end