2012-08-01 57 views
0

在這裏,我有一些代碼:(Corona SDK)如何取消math.random?

function CountDown() 
      if(time_remaining > 1)then 
       time_remaining = time_remaining - 1; 
       print ("Loading menu") 
        local function main(event) 

        -- LAUNCH A ROCKET 
        if math.ceil(math.random() * 200) == 10 and launch == false then 
         Particles.GetEmitter ("Launcher1").rotation = -35 
         Particles.GetEmitter ("Launcher2").rotation = 20 
         Particles.StartEmitter("Launcher1", true) 
         Particles.StartEmitter("Launcher2", true) 

        end 

        -- UPDATE PARTICLES 
        Particles.Update() 

       end 

       -- timer.performWithDelay(33, main, 1) 
       Runtime:addEventListener("enterFrame", main) 
      else 
       time_remaining = 0 
       print ("Load Go!") 
       menuLoad = transition.to(menuLoad, { time=575, y=-500 }) 
      end 

     end 

     count_timer = timer.performWithDelay(1000, CountDown, time_total); 

當我轉我的場景,我通過Particles.CleanUp()取消所有的發射器,但我無法取消的Math.random,它會嘗試反正我開始發射,但由於他們已經是零(Particles.CleanUp),所以它給了我一個錯誤

Runtime error 
    ...me development/Skipjack Rollout Design2/mainmenu.lua:560: attempt to index a nil value 
stack traceback: 
    [C]: ? 
    ...me development/Skipjack Rollout Design2/mainmenu.lua:560: in function <...me development/Skipjack Rollout Design2/mainmenu.lua:556> 
    ?: in function <?:226> 

請幫助我!我如何取消math.random? 在此先感謝!

回答

0

我不完全清楚你在這裏問什麼,但似乎你有幾個問題。

  1. 你已經失去的句柄,您已經添加爲框架監聽器的主要功能
  2. 您不斷每次加它,你檢測TIME_REMAINING> 1,意味着它每運行多次框架
  3. 你和一個計時器句柄來替換你的參考MENULOAD(雖然這可能是故意的。

我從您希望顆粒爲TIME_TOTAL秒,此時你玩代碼推斷會過渡到menuLoad?如果是,那麼下面的內容呢? g:

local function main(event) 
    -- LAUNCH A ROCKET 
    if math.ceil(math.random() * 200) == 10 and launch == false then 
     Particles.GetEmitter ("Launcher1").rotation = -35 
     Particles.GetEmitter ("Launcher2").rotation = 20 
     Particles.StartEmitter("Launcher1", true) 
     Particles.StartEmitter("Launcher2", true) 
    end 

    -- UPDATE PARTICLES 
    Particles.Update() 
end 

Runtime:addEventListener("enterFrame", main) 
timer.performWithDelay(time_total * 1000, function() 
    Runtime:removeEventListener("enterFrame", main) 
    transition.to(menuLoad, { time=575, y=-500 }) 
end)