如果已占用,则将对象分布在2行 - Corona SDK

时间:2016-08-31 14:16:25

标签: lua corona

嘿所以我一直想弄明白但没有运气。我有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

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

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