如何删除所有同名对象

如何删除所有具有相同名称的对象?如果我使用以下命令:

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

它只会删除最新生成的一个,而不是所有相同名称的对象。

点赞
用户2469861
用户2469861

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

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