【问题标题】:Why is this function not making multiple bullets?为什么这个函数不能产生多个子弹?
【发布时间】:2011-08-14 08:09:05
【问题描述】:

我正在开发一个可以发射多发子弹的功能:

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 不太熟悉,如果我做的事情明显错误,或者我没有提供足够的信息(如果您需要更多信息,请询问),我很抱歉。

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    糟糕,我应该更加关注 API:

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

    timer.performWithDelay(10, shootBullets)
    

    到这里:

    timer.performWithDelay(10, shootBullets, 0)
    

    现在有子弹了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      • 2017-02-26
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      相关资源
      最近更新 更多