How to spawn object in tilemap grid (Match-3 mechanics)

Hello!

I’m making a game and took part of the code from an open source example of a match-3 game on Defold, I need to fill the tilemap cells with elements, in this case marshmallows. How to do it? I can’t do it and everything is moving away. Can I spawn an object exactly in the center of the cell? Or if not, how best to do it. Maybe we should abandon tilemaps?

The size of the tile sprite is 256x256, however, to fit the screen size I reduced the scale of the tilemap collection to 0.23

Here is my code:

local function brick_pos(x, y)
	return vmath.vector3(x * 64, y * 64, 0.01)
end


local function populate_level(self)
	local x, y, w, h = tilemap.get_bounds("board#board")
	print("x: " .. w .. " h: " .. h .. " y: " .. y .. " w: " .. w)

	for ix = x, x + w - 1 do
		for iy = y, h + y - 1 do
			local pos = brick_pos(ix, iy)
			local props = {}
			local ids = collectionfactory.create("#elemfactory", pos, nil, props)
			local brick = ids[hash("/element")]
		end
	end
end

function init(self)
	self.bricks = {}
	self.completed = false
	populate_level(self)
end

Help me please.



I would probably not use tilemaps. Game objects with sprites seem more convenient and should give you better control of positions etc

How then can I make a visual grid? I wouldn’t want objects to just hang in the air. Should I just adjust the size of the background sprite or use the GUI?

Perhaps using more game objects with sprites? Can you show a visual example of what you wish to achieve?

I want the objects to be arranged as follows, and they could only be moved horizontally, the grid is visible here

So how can you correctly spawn objects so that everyone is in their own cell, without using a tilemap?

Create a grid of game objects with sprites at fixed positions. This is what I do in my match-3 “engine”:

Thanks, i’ll see

Should we add the sprites of the cells themselves after? That is, take the tilemap and adjust it to fit the spawned objects?