如果已被占用,则将对象分布在 2 行中 - Corona SDK
Spread objects across 2 rows if already occupied - Corona SDK
嘿,所以我一直在努力解决这个问题,但没有运气。我有 8 个随机生成的生成点,它们应该生成 2 行,每行 4 个。我遇到的问题是所有 8 个生成点似乎只在顶行生成。
所以基本上是这样的:
[1][2][3][4][5][6][7][8]
[ ] [ ] [ ] [ ]
什么时候应该是这样:
[1][2][3][4]
[5][6][7][8]
我理解这与我将每个球体定位在 Y 轴的中心但不确定如何做到这一点有关,以便如果 4 个位置被占用,则向下移动到第二行。
干杯,
生成代码
function spawnBase()
shuffleOrbArray(orbList)
for i=1, #orbList do
local orbName = orbList[i]
local posX = (i-1)*67+60
if orbName == "red" then
redPlace = display.newImageRect("Shapes/red-placeholder.png", 57,57)
redPlace.y = _H/2
redPlace.x = posX
redPlace.alpha = 1
redPlace.id = "Red"
orbName:insert(redPlace)
redPlace:addEventListener("tap", revealColor)
elseif orbName == "green" then
--create green enemy
greenPlace = display.newImageRect("Shapes/green-placeholder.png", 57,57)
greenPlace.y = _H/2
greenPlace.x = posX
greenPlace.alpha = 1
greenPlace.id = "Green"
orbName:insert(greenPlace)
greenPlace:addEventListener("tap", revealColor)
elseif orbName == "yellow" then
--create green enemy
尝试这样的事情:
local cols = 4
local orbList = { "a", "b", "c", "d", "e", "f", "g", "h" }
for i=1, #orbList do
local c = ( i - 1 ) % cols
local r = math.floor( ( i - 1 ) / cols)
print( c, r, orbList[i] )
local posX = c * sizeX
local posY = r * sizeY
end
您可以在此处查看 Corona/Lua 中的游戏示例:https://github.com/estudiolune/corona-sdk/tree/master/br3ak
嘿,所以我一直在努力解决这个问题,但没有运气。我有 8 个随机生成的生成点,它们应该生成 2 行,每行 4 个。我遇到的问题是所有 8 个生成点似乎只在顶行生成。
所以基本上是这样的:
[1][2][3][4][5][6][7][8]
[ ] [ ] [ ] [ ]
什么时候应该是这样:
[1][2][3][4]
[5][6][7][8]
我理解这与我将每个球体定位在 Y 轴的中心但不确定如何做到这一点有关,以便如果 4 个位置被占用,则向下移动到第二行。
干杯,
生成代码
function spawnBase()
shuffleOrbArray(orbList)
for i=1, #orbList do
local orbName = orbList[i]
local posX = (i-1)*67+60
if orbName == "red" then
redPlace = display.newImageRect("Shapes/red-placeholder.png", 57,57)
redPlace.y = _H/2
redPlace.x = posX
redPlace.alpha = 1
redPlace.id = "Red"
orbName:insert(redPlace)
redPlace:addEventListener("tap", revealColor)
elseif orbName == "green" then
--create green enemy
greenPlace = display.newImageRect("Shapes/green-placeholder.png", 57,57)
greenPlace.y = _H/2
greenPlace.x = posX
greenPlace.alpha = 1
greenPlace.id = "Green"
orbName:insert(greenPlace)
greenPlace:addEventListener("tap", revealColor)
elseif orbName == "yellow" then
--create green enemy
尝试这样的事情:
local cols = 4
local orbList = { "a", "b", "c", "d", "e", "f", "g", "h" }
for i=1, #orbList do
local c = ( i - 1 ) % cols
local r = math.floor( ( i - 1 ) / cols)
print( c, r, orbList[i] )
local posX = c * sizeX
local posY = r * sizeY
end
您可以在此处查看 Corona/Lua 中的游戏示例:https://github.com/estudiolune/corona-sdk/tree/master/br3ak