【问题标题】:spawning objects not removing after leaving scene离开场景后产生的物体没有被移除
【发布时间】:2013-06-22 13:56:33
【问题描述】:

您好,我的物体在离开场景后没有移除,我试图清除并移除场景,但物体会继续在另一个场景中生成?

local badclout1 = {} 
local bad1Group = display.newGroup()
local function spawnBC1()
   local badclouts1 = display.newImage("BCloud1.png")
   badclouts1.x = math.random(0, _W)
   physics.addBody( badclouts1, "dynamic", { density=.1, bounce=.1, friction=.2, radius=45 } )       
   badclouts1.name = "BCloud1" 
   badclouts1.bodyType = "kinematic"
   badclouts1.isSensor = true
   badclouts1.y = math.random(-100, -50)
   badclouts1.index = #badclout1 + 1
   bad1Group:insert(badclouts1)
   badclouts1.rotation = math.random(-10,10) -- Rotate the object
   badclouts1:setLinearVelocity(0, math.random(speeda1, speedb1)) -- Drop down
   badclout1[badclouts1.index] = badclouts1
   tmrSpawn1 = timer.performWithDelay(math.random(spawna, spawnb), spawnBC1)
return badclouts1 
end
tmrSpawn1 = timer.performWithDelay(math.random(1000, 10000), spawnBC1)
 local function removeBomb()
  for i, v in pairs(badclout1) do
    if badclout1[i].y >1000 then
        badclout1[i]:removeSelf()
        badclout1[i] = nil
     end
  end
end
Runtime:addEventListener("enterFrame", removeBomb)

我的代码中有什么东西可以让它显示在屏幕上吗?

【问题讨论】:

    标签: lua coronasdk corona-storyboard


    【解决方案1】:

    您需要使用timer.cancel(tmrSpawn1) 取消您的performWithDelay 功能。因为你是递归调用它,所以它会一直运行,直到你取消它。

    【讨论】:

    • 没有重新开始,因为我没有正确使用故事板
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多