Hello, i have a stabbing problem. I tried to speed up the process of generating islands by using a larger number of smaller atlases. Of course, I try to generate different objects, but when I create a second object with an atlas to generate an island, the first island is automatically drawn on it without adding a script to the new object. The same thing happens when I change the name of an object and an atlas. Don’t know where the mistake is?
And here is the script:
local perlin = require('main.perlin_noise')
local rgb = hash('rgb')
perlin:load()
local colors = {
water = 255 * vmath.vector3(0.2, 0.5, 1),
sand = 255 * vmath.vector3(1, 0.9, 0.6),
grass = 255 * vmath.vector3(0.2, 0.8, 0.4),
forest = 255 * vmath.vector3(0.1, 0.6, 0.2),
rock = 255 * vmath.vector3(0.7, 0.7, 0.7),
snow = 255 * vmath.vector3(1, 1, 1)
}
local function set_pixel(stream, width, x, y, color)
local index = 3 * (x + y * width) + 1
stream[index] = color.x
stream[index + 1] = color.y
stream[index + 2] = color.z
end
function init(self)
local width = 256
local height = 256
self.buffer = buffer.create(width * height, {{name = rgb, type = buffer.VALUE_TYPE_UINT8, count = 3}})
local stream = buffer.get_stream(self.buffer, rgb)
local scale = 1 / 30
pos = vmath.vector3(128, 128, 0)
radius = 200
for x = 0, width - 1 do
for y = 0, height - 1 do
local v = 0.5 + perlin:noise(x * scale, y * scale, 0) / 2
distance = vmath.length(vmath.vector3(x, y, 0) - pos)
if distance < radius then
part = distance / (radius/150)
v = v - ((v/100) * part)
else v = 0 end
local color = colors.rock
if v < 0.1 then
color = colors.water
elseif v < 0.13 then
color = colors.sand
elseif v < 0.32 then
color = colors.grass
elseif v < 0.40 then
color = colors.forest
elseif v > 0.5 then
color = colors.snow
end
set_pixel(stream, width, x, y, color)
end
end
local resource_path = go.get('#sprite', 'texture0')
local header = {width = width, height = height, type = resource.TEXTURE_TYPE_2D, format = resource.TEXTURE_FORMAT_RGB, num_mip_maps = 1}
resource.set_texture(resource_path, header, self.buffer)
end