enemies = {}
function spawnEnemy(x, y)
local enemy = world:newRectangleCollider(x, y, 22, 32, {collision_class = "Danger"})
enemy.dir = 1
enemy.speed = 100
enemy.animation = animations.enemy
enemy.scale = 1.2
table.insert(enemies, enemy)
end
function updateEnemies(dt)
for i, e in ipairs(enemies) do
e.animation:update(dt)
local ex, ey = e:getPosition()
local colliders = world:queryRectangleArea(ex + (11 * e.dir), ey + 16, 10, 10, {'Plataform'})
if #colliders == 0 then
e.dir = e.dir * -1
end
e:setX(ex + e.speed * dt * e.dir)
end
end
function drawEnemies()
for i, e in ipairs(enemies) do
local ex, ey = e:getPosition()
e.animation:draw(sprites.enemySheet, ex, ey, nil, e.scale * e.dir, e.scale, 17, 19)
end
end
Hello, welcome to the forums. I may be wrong, but I think what's happening is that you have a single animation (animations.enemy) for all the enemies, and you update it once per enemy, therefore the more enemies you have, the more times in the same frame the animation will be updated.
If you're OK with a synchronized animation for all enemies, then you need to update it just once per frame, i.e. you can do animations.enemy:update(dt) out of the per-enemy loop.
If you want the animations to be independent, however, you need a new animation per enemy. You can do that by changing this:
pgimeno wrote: ↑Wed Apr 24, 2024 5:07 am
Hello, welcome to the forums. I may be wrong, but I think what's happening is that you have a single animation (animations.enemy) for all the enemies, and you update it once per enemy, therefore the more enemies you have, the more times in the same frame the animation will be updated.
If you're OK with a synchronized animation for all enemies, then you need to update it just once per frame, i.e. you can do animations.enemy:update(dt) out of the per-enemy loop.
If you want the animations to be independent, however, you need a new animation per enemy. You can do that by changing this:
pgimeno wrote: ↑Wed Apr 24, 2024 5:07 am
Hello, welcome to the forums. I may be wrong, but I think what's happening is that you have a single animation (animations.enemy) for all the enemies, and you update it once per enemy, therefore the more enemies you have, the more times in the same frame the animation will be updated.
If you're OK with a synchronized animation for all enemies, then you need to update it just once per frame, i.e. you can do animations.enemy:update(dt) out of the per-enemy loop.
If you want the animations to be independent, however, you need a new animation per enemy. You can do that by changing this:
I would suggest making the jump from anim8 to rolling your own animation functions is not hard. If you're new to Lua or Love then keep doing what you're doing but consider learning about quads and tracking frames in your own table. You'll find stepping up to that level is not really hard and you'll have more options available to you.