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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Galbrain
Prole
Posts: 2
Joined: Sat May 02, 2015 11:09 pm
Location: Germany

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

Post 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
Attachments
AnimationTest.love
(319.79 KiB) Downloaded 76 times
Shaddy
Prole
Posts: 5
Joined: Thu Apr 30, 2015 11:26 pm

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

Post 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.
Galbrain
Prole
Posts: 2
Joined: Sat May 02, 2015 11:09 pm
Location: Germany

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

Post 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.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

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

Post 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 ;)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest