thanks, your help was great, I will share my code:
function init(self)
msg.post(".","acquire_input_focus")
self.buttons = {}
--Start buttons position
local startX = 1
local startY = 1
--Space between buttons
local xSpace = 10
local ySpace = 10
--Number rows and colums
local rows = 2
local columns = 3
--Tot level buttons
local nButtons = rows * columns
--Save every button id in a table
for i=1,nButtons do
table.insert(self.buttons, "btnNivel" .. i - 1)
end
--Get the button size
local button_size = gui.get_size(gui.get_node("btnNivel0"))
--Get the total width to center buttons x-axis
local tot_width = button_size.x * columns + xSpace * columns
local screen_width = tonumber(sys.get_config("display.width"))
--Get the total height to center buttons y-axis
local tot_height = button_size.y * rows + ySpace * rows
local screen_height = tonumber(sys.get_config("display.height"))
--Calculate the start position for buttons
startX = screen_width / 2 - (tot_width / 2) - button_size.x / 2 - xSpace / 2
startY = screen_height / 2 - (tot_height / 2) - button_size.y / 2 - ySpace / 2
--Set the correct position
local totButtons = 1
while totButtons < nButtons do
for fil=1,rows do
for col=1,columns do
local button = gui.get_node(self.buttons[totButtons])
local posX = startX + (col) * button_size.x + xSpace * col
local posY = startY + (fil) * button_size.y + ySpace * fil
gui.set_position(button, vmath.vector3(posX, posY ,0))
totButtons = totButtons + 1
end
end
end
end
function final(self)
msg.post(".","release_input_focus")
end
function on_input(self, action_id, action)
if action_id == hash("click") and action.pressed then
for i=1,#self.buttons do
local button = gui.get_node(self.buttons[i])
if gui.pick_node(button, action.x, action.y) then
print("click button")
break
end
end
end
end
you need have 6 nodes with name “btnNivel0”, “btnNivel1”…“btnNivel6” if you need add more levels, add more nodes “btnNivel7”…“btnNivelXXX”
I accept suggestions
PS: I will try to make one node and clone it with code and set_id “btnNivel0”…“btnNivelXXX”