android - 电晕SDK : remove objects after delay

标签 android ios iphone coronasdk

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

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

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

我该怎么办? 谢谢!

最佳答案

尝试以下代码:

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

代替:

timer.performWithDelay(20000,removeBody(cloud))

继续编码................ 😃

关于android - 电晕SDK : remove objects after delay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19529514/

相关文章:

iphone - 触摸事件不适用于 UIScrollView 内的 UIView

Android:ListFragment:如何刷新列表

ios - 无法覆盖 UIViewController 中的 UITableView 委托(delegate)方法

android - 什么是 LinearLayoutICS?

ios - 我如何在 Swift 2 中获得 SKSpriteNode 的真正中心?

ios - 如何使用按钮处理 UITableViewCell 中的多点触控?

ios - 供应配置文件不包含在钥匙串(keychain)中安装匹配私钥的任何证书

objective-c - 如何在等待 NSURL 连接完成时阻止 objective-c 方法的执行?

java - 如何修复 "Can' t 通过此策略定位元素 : Locator map:"

android - 多个字符集 : text/json; Charset=UTF-8;charset=utf-8 OkHttp Header