[SOLVED] Out of tiles to render. Help with world segment generation with tilesets

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!

Do you get this error immediately when starting the game or after a while? If it happens after a while make sure to also delete segments that are outside of the view.

1 Like

It’s just as it starts. On the game screen there’s a second of nothing happening and right after both the bottom and top of the wall disappear leaving only the green tileset without moving or anything.

I might try taking off those two parts as they seem to be the ones that are popping out of existence

How often are you spawning new segments? From the code you shared it looks like it happens once when self.spawn_free is set to true in init(). You also set self.spawn_free in on_message when the “spawn_free” message is received. How often does that happen?

1 Like

It should spawn a new segment every time the previous position_maker.go (which is positioned at the edge of the 512x512 segment) is bellow the 512pixel on the X axis of the main collection.

So it shouldn’t be that often, unless I’m understanding wrong how I wrote the code and it’s spawning the segments constantly and that’s why isn’t working properly

1 Like

I’ve solved the issue! I had my factory at 0,0 when it should’ve been at 512, 0.

So now that error doesn’t occur! Now I only need to work on the segments so they can move, thanks for the help!

2 Likes

Changed the “go.delete()” to “go.delete(true)” and that did the trick to delete the parent and its child contents

1 Like