Handling a animation multiple times - can't figure it out
Posted: Sun May 03, 2015 12:06 am
I am new to Love2d and also to lua, so i need some help. I was trying to make some animations with AnAL and some easy animations came up. But at the moment i have a problem and can't figure out what i need to do to make it work. I want to create a explosion from the same spritesheet multiple times. My biggest problem now is that i don't know how i combine a table with AnAL functions. I found some similar threads, but those don't gave me a solution for my specific problem. It would be nice if someone could show me a little example how i can create multiple explosions without deleting the first one by starting a new or just show me what i have done wrong.
And also sorry if my english/gramar is terrible, trying my best at least.
And also sorry if my english/gramar is terrible, trying my best at least.
Code: Select all
require "AnAL"
function love.load()
img = love.graphics.newImage("explosion-spritesheet.png")
animStart = 0 -- this is to prevent the animation from starting without pressing the "right" key, it's just for testing the explosion
anim = {}
end
function love.update(dt)
if animStart == 1 then
for i,v in ipairs(anim) do
v:update(dt)
end
end
end
function love.keypressed( key )
--Beenden des Spiels
if love.keyboard.isDown( "escape" ) then
love.event.quit()
end
if love.keyboard.isDown("right") then
x= math.random(0, 700) -- i am making the x and y random so the animations don't get ovelapped and i can see them at different positions
y = math.random(0, 558)
--trying to make multiple animations
table.insert(anim,{})
for i,v in ipairs(anim) do
v = newAnimation(img, 100, 100, 0.03, 0)
v:setMode("once")
end
animStart = 1
end
end
function love.draw()
if animStart == 1 then
for i,v in ipairs(anim) do
v:draw(x, y)
end
end
end