我对corona sdk中的程序流感到非常困惑。
我想做的是,当过渡结束时,流会继续,我知道我可以使用Oncomplete,但我不知道在这种情况下如何使用它。
我有这个代码:
while ban == 2 do
actual = x
desplazar = x
while actual >= 0 do
actual = actual - 4
if inTable(t,actual) then
while inTable(t,actual) and actual >=0 do
actual= actual - 4
end
end
if actual >= 0 then
banaux=1
if inTable(t, desplazar) then
block[desplazar].value=0
block[desplazar]:removeSelf()
for z=1, tablelength(t) do
if t[z] == desplazar then
t[z]=32
end
end
end
transition.to(block[actual], {time=velocity, x=block[desplazar].x, y=block[desplazar].y})
cambiodesp(actual,desplazar)
desplazar = desplazar - 4
end
end
x = x -1
if inTable(t,x) then
else
ban = 1
end
end
由于转换,我得到了很多意想不到的结果,我认为代码会继续运行,尽管转换还没有完成,我想在转换完成时为运行上面的代码做点什么,但我认为我不能使用oncomplete。
我想在完成后继续运行
transition.to(block[actual], {time=velocity, x=block[desplazar].x, y=block[desplazar].y})
我不理解代码流是如何工作的,所以希望你能向我解释
也许你可以使用这个技巧,但我不建议这样做。因为它可能会阻塞运行时间。我建议你写函数。所以你可以正确使用onComplete方法
无论如何,这里有一个糟糕但快速的解决方法:
while ban == 2 do
actual = x
desplazar = x
while actual >= 0 do
actual = actual - 4
if inTable(t,actual) then
while inTable(t,actual) and actual >=0 do
actual= actual - 4
end
end
if actual >= 0 then
banaux=1
if inTable(t, desplazar) then
block[desplazar].value=0
block[desplazar]:removeSelf()
for z=1, tablelength(t) do
if t[z] == desplazar then
t[z]=32
end
end
end
local isEnded = false
transition.to(block[actual], {time=velocity, x=block[desplazar].x, y=block[desplazar].y, onComplete = function() isEnded = true end })
while isEnded == false then end
cambiodesp(actual,desplazar)
desplazar = desplazar - 4
end
end
x = x -1
if inTable(t,x) then
else
ban = 1
end
end