-2

嗨,如果我使用以下方法,我如何删除所有具有相同名称的对象:

local screenGroup = self.view
local randomBad3 = function()
  badC3 = display.newImage("BCloud3-"..tostring(math.random(1, 12))..".png")
  badC3.x = math.random (0, 450); badC3.y = -50-- -50
  physics.addBody( badC3, { density=.3, bounce=0.3, friction=.3, radius=25, filter=badc3CollisionFilter } )
  badC3.name = "BCloud3"    
  badC3.isSensor = true
  badC3.rotation = math.random(-30,30) -- Rotate the object
  trans5 = transition.to( badC3, { time= math.random(yForB3A, yForB3B), y=600,  transition=easing.OutExpo } )
  badC3.gravityScale = 0.0
  local cleanup
  cleanup = function()
   if badC3 then
       if badC3.y >590 then
           badC3:removeSelf()
           badC3 = nil
       end
   end
end
Runtime:addEventListener("enterFrame", cleanup)
end
randomBadC3 = timer.performWithDelay( math.random(1000, 5000), randomBad3, 0 )

--

   if badC3 then
           badC3:removeSelf()
           badC3 = nil
   end

它只删除最后一个生成的,而不是全部

4

1 回答 1

2

当您要删除整个组时,将所有图像添加到一个组中。

for i=1,#maingroup do
    if maingroup[i] then
        maingroup[i]:removeSelf();maingroup[i]=nil
    end
end
end
于 2013-09-11T11:34:52.470 回答