我收到此错误:
尝试索引?一个零值
在更新功能的开始。可能是什么原因?
--Create drop
local createDrop=function()
drop = display.newImage("drop.png")
drop.x=math.random(drop.width, W-drop.width); drop.y=-50
drop.type="drop"
drops:insert(drop)
physics.addBody(drop)
print(drops.numChildren)
end
local dropTimer = timer.performWithDelay ( 1000, createDrop, 0)
--Remove the drops that is out of screen
local function update()
for i=1,drops.numChildren do
if(drops[i].y>H) then
drops[i]:removeSelf()
drops[i] = nil
end
end
end
--Runtime:addEventListener("enterFrame", function() print(drop.y) end) --to check if the drop that is out off screen is removed.
Runtime:addEventListener("enterFrame", update)