2016-08-31 39 views
0

嘿所以我一直试图弄清楚这一点,但没有运气。我有8个随机洗牌的产卵,他们应该产卵两行4。我遇到的问题是,所有8似乎只产卵在第一排。传播对象 - 科罗娜SDK

所以基本上这样:
[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 
+0

什么是'_H/2'吗? – hjpotter92

+0

噢,对此感到抱歉。 _H/2基本上是display.content高度除以2.它意味着中心高度。 –

+0

您可以更新'i> 4'的这个值。 – hjpotter92

回答

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 

你可以看看这里科罗纳游戏采样/ Lua的:https://github.com/estudiolune/corona-sdk/tree/master/br3ak

+0

嘿麦孔,感谢您的帮助。什么是sizeX和sizeY值? –

+0

@DipeshDhanji大小是你的Orb(宽度,高度)的值。 –

+0

我明白了,非常感谢您的帮助 –