【问题标题】:Corona SDK: remove objects after delayCorona SDK:延迟后删除对象
【发布时间】:2013-10-22 22:28:10
【问题描述】:

我正在我的游戏中创建云,我想在 20 秒后将其移除。问题是当我添加删除它们的代码时,云甚至没有出现,似乎它们在创建时就被删除了。

以下是我已经尝试过的 2 种方法(均无效):

local function removeBody(body)

    body:removeSelf()
end

local function newCloud()
    local n = cloudNumber
    while n==cloudNumber do
    n = math.random(1,5)
end
    cloudNumber=n
    local cloud = display.newImage(imageNames[cloudNumber], screenW+30, screenH*0.2)
    timer.performWithDelay(6000, newCloud)
    cloud.myName="cloud"
    physics.addBody (cloud, {isSensor=true})
    cloud:setLinearVelocity(-25,0)
    cloud.gravityScale=0
    timer.performWithDelay(20000,removeBody(cloud))
end

local function newCloud()
    local n = cloudNumber
    while n==cloudNumber do
    n = math.random(1,5)
end
    cloudNumber=n
    local cloud = display.newImage(imageNames[cloudNumber], screenW+30, screenH*0.2)
    timer.performWithDelay(6000, newCloud)
    cloud.myName="cloud"
    physics.addBody (cloud, {isSensor=true})
    cloud:setLinearVelocity(-25,0)
    cloud.gravityScale=0
    --timer.performWithDelay(20000, cloud:removeSelf())
end

我该怎么办? 谢谢!

【问题讨论】:

    标签: android ios iphone coronasdk


    【解决方案1】:

    试试下面的代码:

    timer.performWithDelay(20000,function() cloud:removeSelf() end)
    

    代替:

    timer.performWithDelay(20000,removeBody(cloud))
    

    继续编码...... ?

    【讨论】:

      猜你喜欢
      • 2012-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 2011-04-09
      相关资源
      最近更新 更多