Page 1 of 1

Handling a animation multiple times - can't figure it out

Posted: Sun May 03, 2015 12:06 am
by Galbrain
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.

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

Re: Handling a animation multiple times - can't figure it ou

Posted: Sun May 03, 2015 3:06 am
by Shaddy
Now Im not entirely sure if there is a better way to do it, but I basically just saved the frame of every different itteration of the animation in a table and ran through that and drew each one. Not sure if it will really work for your idea, but thats how I did it.

Re: Handling a animation multiple times - can't figure it ou

Posted: Sun May 03, 2015 6:54 pm
by Galbrain
Shaddy wrote:Now Im not entirely sure if there is a better way to do it, but I basically just saved the frame of every different itteration of the animation in a table and ran through that and drew each one. Not sure if it will really work for your idea, but thats how I did it.

I think i know what you mean, but i want to work with spritesheets, so there must be another way.

Re: Handling a animation multiple times - can't figure it ou

Posted: Sun May 03, 2015 7:35 pm
by MadByte
Here is an commented example on how you can do this:
MultiplyAnimations.love
If you have further questions, feel free to write me a pm in german ;)