Basically, as an enemy goes off the left side of the screen, it is removed from the table -- however, the next enemy in the table after it, will twitch backwards. Also when an enemy is removed (for example, colliding with a projectile) the enemy behind it, or after it in the table order, will twitch backwards aswell.
In the example below, the squares would be enemies.
Here is a simplified example showing the bug; (watch the left side of the screen) The code, if you cannot test the attachment:
Code: Select all
square = {}
square.w = 40
square.h = 40
square.x = love.graphics.getWidth()
square.y = math.random (0,love.graphics.getHeight()-20)
square.xvel = 200
square.yvel = 0
square.cycle = 0
square.delay = 0.5
square.objects = {}
function love.update(dt)
square.cycle = math.max(0, square.cycle - dt)
if square.cycle <= 0 then
table.insert(square.objects, {
x = love.graphics.getWidth(),
y = math.random (0,love.graphics.getHeight()-square.h),
r = math.random(100,255),
g = math.random(100,255),
b = math.random(100,255),
})
square.cycle = square.delay
end
for i,s in pairs(square.objects) do
s.x = s.x - square.xvel *dt
if s.x < 0-square.w then
table.remove(square.objects, i)
end
end
end
function love.draw()
for _,s in pairs(square.objects) do
love.graphics.setColor(s.r,s.g,s.b,255)
love.graphics.rectangle("line", s.x,s.y,square.w,square.h)
end
end
function love.keypressed(key)
if key == "escape" then love.event.quit() end
end