如何将lua中的图片排列成网格状?
How to arrange picture in lua like a grid?
我正在学习 lua,我想用一些特定的 x 和 y 坐标排列我的气泡图片,这是我目前的代码,我的 j 和 i 的值只增加 1 而不是+29,我知道我缺乏一些知识,所以任何帮助将不胜感激
local background = display.newImageRect("blueBackground.png",642, 1040)
background.x = display.contentCenterX
background.y = display.contentCenterY
local x = 15
local y=15
for i=15,25 do
for j=15, 25 do
local bubble = display.newImageRect("bubble.png", 23,23)
bubble.x = i
bubble.y = j
j = j + 29
print("j",j)
end
i = i + 29
print("i",i)
end
这应该对你有帮助。
来自 Lua documentation
The for
statement has two variants: the numeric for and the
generic for.
A numeric for
has the following syntax:
for var=exp1,exp2,exp3 do
something
end
That loop will execute something for each value of var
from exp1
to exp2
, using exp3
as the step to increment var. This third
expression is optional; when absent, Lua assumes one as the step
value. As typical examples of such loops, we have
for i=1,f(x) do print(i) end
for i=10,1,-1 do print(i) end
使用
for i=15, 29*10+15, 29 do
for j=15, 29*10+15, 29 do
local bubble = display.newImageRect("bubble.png", 23,23)
bubble.x = i
bubble.y = j
print("j",j)
end
print("i",i)
end
或
for i=0, 10 do
for j=0, 10 do
local bubble = display.newImageRect("bubble.png", 23,23)
bubble.x = 15 + i * 29
bubble.y = 15 + j * 29
...
我正在学习 lua,我想用一些特定的 x 和 y 坐标排列我的气泡图片,这是我目前的代码,我的 j 和 i 的值只增加 1 而不是+29,我知道我缺乏一些知识,所以任何帮助将不胜感激
local background = display.newImageRect("blueBackground.png",642, 1040)
background.x = display.contentCenterX
background.y = display.contentCenterY
local x = 15
local y=15
for i=15,25 do
for j=15, 25 do
local bubble = display.newImageRect("bubble.png", 23,23)
bubble.x = i
bubble.y = j
j = j + 29
print("j",j)
end
i = i + 29
print("i",i)
end
这应该对你有帮助。
来自 Lua documentation
The
for
statement has two variants: the numeric for and the generic for.A numeric
for
has the following syntax:for var=exp1,exp2,exp3 do something end
That loop will execute something for each value of
var
fromexp1
toexp2
, usingexp3
as the step to increment var. This third expression is optional; when absent, Lua assumes one as the step value. As typical examples of such loops, we havefor i=1,f(x) do print(i) end for i=10,1,-1 do print(i) end
使用
for i=15, 29*10+15, 29 do
for j=15, 29*10+15, 29 do
local bubble = display.newImageRect("bubble.png", 23,23)
bubble.x = i
bubble.y = j
print("j",j)
end
print("i",i)
end
或
for i=0, 10 do
for j=0, 10 do
local bubble = display.newImageRect("bubble.png", 23,23)
bubble.x = 15 + i * 29
bubble.y = 15 + j * 29
...