我收到此錯誤顯示對象:得到錯誤,而試圖刪除沒有用了
學嘗試索引?一個零值
在更新功能的開始。可能是什麼原因?
--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)
是否有滴'下降[drops.numChildren]'進入?還是那個在桌子的盡頭?找出哪條線(以及循環的哪個迭代)導致錯誤,這也有助於調試。 –