Lua 如何删除具有相同名称的所有对象

Lua 如何删除具有相同名称的所有对象,lua,coronasdk,Lua,Coronasdk,嗨,如果我使用以下命令,如何删除所有同名对象: 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

嗨,如果我使用以下命令,如何删除所有同名对象:

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 )
--


当您要删除整个组时,它只删除最后生成的图像,而不是所有图像

将所有图像添加到一个组中

for i=1,#maingroup do
    if maingroup[i] then
        maingroup[i]:removeSelf();maingroup[i]=nil
    end
end
end

从哪里搬走?关于你的问题,你提供的信息太少了。就像洛伦佐说的,信息太少了,甚至无法理解你的意思。你的意思是在一个表中循环并删除badc3值的所有实例吗?@kevin你知道lua中的对象和值并没有真正的名称,对吗?@greatwolf well有点用对象的名称“badc3”。。。
for i=1,#maingroup do
    if maingroup[i] then
        maingroup[i]:removeSelf();maingroup[i]=nil
    end
end
end