更改下拉速度的更好方法

时间:2013-07-08 17:27:26

标签: lua corona

嗨,我得到了这个小的衍生功能,可以从天空中掉落云彩。

local randomBad1 = function()
    local badC1 = display.newImage("BCloud1.png")
    badC1.x = math.random (0, 450); badC1.y = -50
    physics.addBody( badC1, { density=.1, bounce=0.1, friction=.2, radius=45, filter=badc1CollisionFilter } )
    badC1.name = "BCloud1"    
    badC1.isSensor = true
    badC1.rotation = math.random(-20,20) -- Rotate the object
    badC1.gravityScale = 0.40
    local cleanup
    cleanup = function()
       if badC1 then
           if badC1.y >600 then
               badC1:removeSelf()
               badC1 = nil
           end
       end
    end
    Runtime:addEventListener("enterFrame", cleanup)
end
randomBadC1 = timer.performWithDelay( 3000, randomBad1, 0 )

所以我想知道是否有更好的方法来改变降低速度而不是'gravityScale'?

凯文 -

2 个答案:

答案 0 :(得分:2)

您可以使用applyForce对云执行此操作。我在代码中添加了一些行,如下所示:

local randomBad1 = function()
  local badC1 = display.newImage("BCloud1.png")
  badC1.x = math.random (0, 450); badC1.y = 50-- -50
  physics.addBody( badC1, { density=.1, bounce=0.1, friction=.2, radius=45, filter=badc1CollisionFilter } )
  badC1.name = "BCloud1"    
  badC1.isSensor = true
  badC1.rotation = math.random(-20,20) -- Rotate the object

  -------------------------------------------------------------------
            -- These lines will do it for you --
  -------------------------------------------------------------------
  yFor  = math.random(1000)   -- choosing a random y directional Force
  print("yFor = "..yFor)
  badC1:applyForce( 0, yFor, badC1.x, badC1.y )  -- apply the force to your cloud 
  -------------------------------------------------------------------

  badC1.gravityScale = 0.40
  local cleanup
  cleanup = function()
   if badC1 then
       if badC1.y >600 then
           badC1:removeSelf()
           badC1 = nil
       end
   end
end
Runtime:addEventListener("enterFrame", cleanup)
end
randomBadC1 = timer.performWithDelay( 3000, randomBad1, 0 )

有关详细信息,请参阅:Corona Physics Body Properties.

继续编码............:)

答案 1 :(得分:0)

如果云是唯一落下的物体,我会完全改变引力。

physics.setGravity( gx, gy )