Grid view

kjhuKht.png?1

local text = {} local cube = {} col = 0 row = 0 for i = 1 , 12 do cube[i] = display.newRect(0,0,50,50) cube[i].x = col\* 55 +50 cube[i].y = row\*55+ 150 col = col + 1 if col \> 2 then row = row + 1 col = 0 end end for i = 1 , 12 do text[i] = display.newText(i,0,0,"",25) text[i]:setFillColor(0,0,0) text[i].x = cube[i].x text[i].y = cube[i].y end 

How to make the cube10 move to the column 4 and row 1 ?

here is ‘one’ way to do it…  there are lots of ways to do a grid.  I tired to keep your code in tack as much as possible.  Also, I would consider making each qube a display group or container and then have both the ‘rect’ and the ‘text’ as members to it.  I like to keep things that belong together (as the text and the rect appear to in this case) in a container or group. 

local text = {} local cube = {} local horzOffset = 50 local vertOffset = 150 local qubeCnt = 1 cols = 3 rows = 4 for i = 1 , rows do for ii = 1, cols do cube[qubeCnt] = display.newRect(0,0,50,50) cube[qubeCnt].x = (ii \* 55) + horzOffset cube[qubeCnt].y = (i \* 55 ) + vertOffset text[qubeCnt] = display.newText(qubeCnt,0,0,"",25) text[qubeCnt]:setFillColor(0,0,0) text[qubeCnt].x = cube[qubeCnt].x text[qubeCnt].y = cube[qubeCnt].y qubeCnt = qubeCnt + 1 end end

good luck!

Bob

sorry, I may have mis-read your question:

you could try this. I set the offset to a negative value, so all the rects would show on screen.

local text = {} local cube = {} local horzOffset = -30 local vertOffset = 150 local qubeCnt = 1 cols = 3 rows = 3 for i = 1 , rows do for ii = 1, cols do cube[qubeCnt] = display.newRect(0,0,50,50) cube[qubeCnt].x = (ii \* 55) + horzOffset cube[qubeCnt].y = (i \* 55 ) + vertOffset text[qubeCnt] = display.newText(qubeCnt,0,0,"",25) text[qubeCnt]:setFillColor(0,0,0) text[qubeCnt].x = cube[qubeCnt].x text[qubeCnt].y = cube[qubeCnt].y qubeCnt = qubeCnt + 1 end end for i = 4, 6 do cube[qubeCnt] = display.newRect(0,0,50,50) cube[qubeCnt].x = (i \* 55) + horzOffset cube[qubeCnt].y = cube[3].y text[qubeCnt] = display.newText(qubeCnt,0,0,"",25) text[qubeCnt]:setFillColor(0,0,0) text[qubeCnt].x = cube[qubeCnt].x text[qubeCnt].y = cube[qubeCnt].y qubeCnt = qubeCnt + 1 end

here is ‘one’ way to do it…  there are lots of ways to do a grid.  I tired to keep your code in tack as much as possible.  Also, I would consider making each qube a display group or container and then have both the ‘rect’ and the ‘text’ as members to it.  I like to keep things that belong together (as the text and the rect appear to in this case) in a container or group. 

local text = {} local cube = {} local horzOffset = 50 local vertOffset = 150 local qubeCnt = 1 cols = 3 rows = 4 for i = 1 , rows do for ii = 1, cols do cube[qubeCnt] = display.newRect(0,0,50,50) cube[qubeCnt].x = (ii \* 55) + horzOffset cube[qubeCnt].y = (i \* 55 ) + vertOffset text[qubeCnt] = display.newText(qubeCnt,0,0,"",25) text[qubeCnt]:setFillColor(0,0,0) text[qubeCnt].x = cube[qubeCnt].x text[qubeCnt].y = cube[qubeCnt].y qubeCnt = qubeCnt + 1 end end

good luck!

Bob

sorry, I may have mis-read your question:

you could try this. I set the offset to a negative value, so all the rects would show on screen.

local text = {} local cube = {} local horzOffset = -30 local vertOffset = 150 local qubeCnt = 1 cols = 3 rows = 3 for i = 1 , rows do for ii = 1, cols do cube[qubeCnt] = display.newRect(0,0,50,50) cube[qubeCnt].x = (ii \* 55) + horzOffset cube[qubeCnt].y = (i \* 55 ) + vertOffset text[qubeCnt] = display.newText(qubeCnt,0,0,"",25) text[qubeCnt]:setFillColor(0,0,0) text[qubeCnt].x = cube[qubeCnt].x text[qubeCnt].y = cube[qubeCnt].y qubeCnt = qubeCnt + 1 end end for i = 4, 6 do cube[qubeCnt] = display.newRect(0,0,50,50) cube[qubeCnt].x = (i \* 55) + horzOffset cube[qubeCnt].y = cube[3].y text[qubeCnt] = display.newText(qubeCnt,0,0,"",25) text[qubeCnt]:setFillColor(0,0,0) text[qubeCnt].x = cube[qubeCnt].x text[qubeCnt].y = cube[qubeCnt].y qubeCnt = qubeCnt + 1 end