为什么这个功能没有多发子弹?

时间:2011-08-13 23:46:15

标签: lua corona

我正在开发一个功能,可以在这里拍摄多个子弹:

local function shootBullets ( event )
    local bullet = display.newImageRect("images/Bullet.png", 12, 12) --Create the bullet image
    physics.addBody(bullet, "kinematic", {bounce = 0}) --Allow physics stuff to work on it
    bullets:insert( bullet ) --Add it to a global group called "bullets"
    bullet:setLinearVelocity(20, 40) --Give it a velocity

end

我用这个计时器调用它:

timer.performWithDelay(10, shootBullets)

它移动了一颗子弹,但它没有制造新子弹。每次拨打shootBullets ( event )时,如何让它产生新的子弹?我对Lua并不熟悉,如果我做了一些明显错误的事情,或者如果我没有提供足够的信息(如果你需要更多信息,请问),我很抱歉。

1 个答案:

答案 0 :(得分:3)

糟糕,我应该密切关注API:

timer.performWithDelay(time, function, times)的默认3参数是1.为了让它永远重复,我需要将其设为0.所以我改变了:

timer.performWithDelay(10, shootBullets)

对此:

timer.performWithDelay(10, shootBullets, 0)

现在有子弹。