I activated the space key to redraw the objects with exactly the same parameters and positions and the second time this is done everything is in the correct position.
local function create_letterbox(letter, pos, scale)
local component = "/leterbox_factory#letterbg_factory"
local c = factory.create(component, pos)
go.set_scale(scale, c)
-- go.set_position(pos, c) -- tried this with same result
msg.post(c, hashes.SET_LETTER, { letter = letter })
return c
end
function draw_board()
for _, word_map in pairs(board_def.words_map) do
for _, letter_map in ipairs(word_map) do
local obj = letter_map.obj
if board_def.objects[obj] == "" then
local pos = vmath.vector3(sizes.left, sizes.top, 0)
local letterobj = create_letterbox(letter_map.letter, pos, sizes.letterbox_scale)
letter_map.pos = {x = pos.x, y = pos.y}
board_def.objects[obj] = letterobj;
end
end
end
code do clear all letterbox
local function clear_board()
print("clear_board")
for obj, object in pairs(board_def.objects) do
go.delete(object)
board_def.objects[obj] = ""
end
end
Code to perform the tests.
Touch the screen calculates the positions and generates a new scheme.
Space deletes and recreates with the same parameters already calculated.
function on_input(self, action_id, action)
if action_id == hashes.TOUCH and action.pressed then
clear_board()
create_board() -- Create call draw_board()
elseif action_id == hashes.SPACE and action.pressed then
clear_board()
draw_board()
end
end
function draw_board()
for _, word_map in pairs(board_def.words_map) do
for _, letter_map in ipairs(word_map) do
local obj = letter_map.obj
if board_def.objects[obj] == "" then
local pos = vmath.vector3(letter_map.pos_x, letter_map.pos_y, 0)
local letterobj = create_letterbox(letter_map.letter, pos, sizes.letterbox_scale)
board_def.objects[obj] = letterobj;
end
end
end
end
I saw a message stating that the maximum number of collisions (64) had been reached, and the messages were no longer being processed.
I eliminated the object collision and the error no longer occurred.
Before I changed go.delete(object, true) to delete the letterbox recursively but it didn’t work.
Wouldn’t it have to exclude the collisions that are inside it?
Anyway, I don’t need these collisions at the moment.
I was running via vs code (defold kit), and I don’t remember seeing this message about collisions. I saw it when I run through the defold editor.