如果已经占用,将对象分布在两行上 - Corona SDK

嘿,我一直在试图弄清楚这个问题,但是没有成功。我有8个生成点,它们应该沿着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
点赞
用户6312494
用户6312494

尝试像这样:

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

2016-09-02 12:19:36