(Corona SDK)如何取消math.random?
这里我有一些代码:(Corona SDK)如何取消math.random?,math,random,sdk,coronasdk,Math,Random,Sdk,Coronasdk,这里我有一些代码: function CountDown() if(time_remaining > 1)then time_remaining = time_remaining - 1; print ("Loading menu") local function main( event ) -- LAUNCH A
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);
切换场景时,我会按粒子.CleanUp()取消所有发射器,但我无法取消math.random,它仍会尝试启动我的发射器,但因为它们已经为零(粒子.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>
运行时错误
…me开发/Skipjack卷展栏设计2/Main菜单。lua:560:尝试索引零值
堆栈回溯:
[C] :?
…me开发/Skipjack卷展栏设计2/Main菜单。lua:560:功能中
?:在函数中,我不完全清楚你在问什么,但似乎你有几个问题
您丢失了作为帧侦听器添加的主函数的句柄
每次检测到剩余时间>1时,您都会重复添加它,这意味着它每帧运行多次
您正在用计时器句柄替换对menuLoad的引用(尽管这可能是有意的)
我从代码中推断,您希望您的粒子播放时间为总秒,在这一点上您将过渡到menuLoad?如果是,那么以下情况如何:
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)