Hi! As the title says I need help with generating world “segments” for my game.
I want for my game to spawn “pre build” world segments that would come one after the other and stich them together.
Here’s an example of one segment
But I run the next following issue in the console:
ERROR:GAMESYS: Out of tiles to render (8192). You can change this with the game.project setting tilemap.max_tile_count
ERROR:GAMESYS: Tilemap could not be created since the tilemap buffer is full (256). You can change this with the config setting tilemap.max_count
The settings are already higher than they were before but it still isn’t enough.
As how I’m generating these segments I’m using collections and factories similar to the ones argued in these topics
Endless Runner Segment generation
Endless Runner Segment Generation Fully Solved
Mixed with some of the code shown in the Defold’s Manual for an Endless runnner and tips and code from a coworker’s project
I intend for them to be able to spawn with different probabilities so it isn’t that repetitive.
local probability = {
[1] = 100,
[2] = 0,
[3] = 0,
[4] = 0
}
local function level_random(max)
local lvl
local random = math.random(1, max)
if random <= probability[1] then
lvl = 1
elseif random <= probability[1] + probability[2] then
lvl = 2
elseif random <= probability[1] + probability[2] + probability[3] then
lvl = 3
elseif random <= probability[1] + probability[2] + probability[3] + probability[4] then
lvl = 4
end
return lvl
end
function init(self)
self.probability_max = 0
for i = 1, #probability do
self.probability_max = self.probability_max + probability[i]
end
math.randomseed(tonumber(hash_to_hex(hash(tostring({}))):sub(4, 8), 16))
self.spawn_free= true
end
function on_message(self, message_id, message, sender)
if message_id == hash("spawn_free") then
self.spawn_free = true
end
end
function update(self, dt)
if self.spawn_free then
self.spawn_free = false
local pos = go.get_position()
pos.y = 0
local component = "/level_gen_factory#level_gen_factory_" ..level_random(self.probability_max)
local level = collectionfactory.create(component, pos)
for key, value in pairs(level) do
msg.post(value, "start_animation", { delay = 0.3 * math.random()})
msg.post(value, "disable_spawncheck")
end
end
end
And to make the whole segment move I use an invisible object named “position_marker” that uses the following script.
function init(self)
self.speed = go.get("/controller#controller", "speed")
self.spawn_free = true
end
function update(self, dt)
local pos = go.get_position()
if self.spawn_free and pos.x < 512 then
self.spawn_free = false
msg.post("/level_gen_factory", "spawn_free")
end
if pos.x < -50 then
go.delete()
end
pos.x = pos.x - self.speed * dt
go.set_position(pos)
end
If it doesn’t seem to have a clear answer I’m going to try to follow all the steps and tips of the other two topics to see if that works.
Thanks in advance for the help!