【问题标题】:Trouble with the flow in lua/corona sdk codeslua/corona sdk 代码中的流程问题
【发布时间】:2013-07-01 01:21:42
【问题描述】:

我对 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})

我不明白代码的流程是如何工作的,所以希望你能向我解释一下

【问题讨论】:

    标签: lua coronasdk corona-storyboard


    【解决方案1】:

    也许你可以使用这个技巧,但我不推荐这个。因为它可能会阻塞运行时间。我建议你写函数。所以你可以正确使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      • 1970-01-01
      • 2012-05-08
      • 2013-06-06
      • 1970-01-01
      相关资源
      最近更新 更多