Code: Select all
for i = 1, 5000 do
local obj = ObjShot(0,0) --generates bullet with default coordinates (0,0)
obj.isDelete = true --ensures that its inactive
shot_all[i] = obj --adds to the shot list
end
Code: Select all
function findDeadBullet()
local x = 0
while true do
x = x + 1
if shot_all[x].isDelete == true then --if bullet object is inactive then it is returned for use
break
end
end
return x
end
I realize now that when there are a lot of bullets already in existence, the findDeadBullet function has to iterate through more of the shot list to find a dead one, which may be significant.
I was wondering if there was a different, more efficient way of handling this. One thing I thought of that was an extension on this was to start the bullet list small and increase its size as needed. This might not have a tangible benefit, however, and may in fact introduce hitches when generating the new dead shots for the size increases.