Animations And LÖVE (AnAL) - The animations replacement lib

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by nevon » Sat Sep 19, 2009 2:59 pm

I'm getting a strange error from AnAL when trying to create a simple animation:
animation.lua:129: attempt to call method 'getHeight' (a nill value)
Here's what I'm doing:

Code: Select all

function love.load()
    anim = love.graphics.newImage("ballanim.png")
    ball.img = newAnimation(anim, 24, 24, 0.1, 6) 
end
function love.update()
    ball.img:update(dt)
end
function love.draw()
    ball.img:draw(ball.x-ballWidth/2, ball.y-ballHeight/2) --obviously these values exist. I'm just showing you the parts dealing with the animation.
end
Here's the image ballanim.png:
Image

I just don't see what I'm doing wrong.

EDIT: It seems AnAL goes apeshit over my use of ball.img. If I change it to something like testball = newAnimation(anim, 24, 24, 0.1, 6) and then change all references to ball.img to testball, it works.

However, after the last frame a single line is displayed. Why is that? My image is 3*24px wide and 2*24px high, and each frame is 24px.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by bartbes » Sat Sep 19, 2009 4:17 pm

Well, I think those issues are related, that specific line is for anim:getHeight(), it gets the height of the current frame, but since you say you have an extra frame... could you tell me the result when you change the frames parameter to 0 (the last one), so it autodetects the amount?

User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by nevon » Sat Sep 19, 2009 4:31 pm

bartbes wrote:Well, I think those issues are related, that specific line is for anim:getHeight(), it gets the height of the current frame, but since you say you have an extra frame... could you tell me the result when you change the frames parameter to 0 (the last one), so it autodetects the amount?
If I change it to 0, the same thing happens. You could try it yourself if you download and run the attached .love file (with Love 0.6.0, obviously). I don't know if it's related to the image or to AnAL.
Attachments
demo.love
(9.56 KiB) Downloaded 275 times

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by bartbes » Sat Sep 19, 2009 5:03 pm

Can you confirm changing lines 49 and 50 to say (i-1) instead of i fixes the problem?

User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by nevon » Sat Sep 19, 2009 5:16 pm

bartbes wrote:Can you confirm changing lines 49 and 50 to say (i-1) instead of i fixes the problem?
No, in fact, that makes it worse.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by bartbes » Sat Sep 19, 2009 5:21 pm

That fixed it for me?!
so, lines 49 and 50 become:

Code: Select all

		local row = math.floor((i-1)/rowsize)
		local column = (i-1)%rowsize

User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by nevon » Sat Sep 19, 2009 5:26 pm

bartbes wrote:That fixed it for me?!
so, lines 49 and 50 become:

Code: Select all

		local row = math.floor((i-1)/rowsize)
		local column = (i-1)%rowsize
That does indeed solve it. I must have made a typo or something, because I thought I did exactly that. :brows:

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by bartbes » Sat Sep 19, 2009 5:31 pm

Bug and fix confirmed, new version!

User avatar
konsumer
Prole
Posts: 7
Joined: Wed Jan 06, 2010 5:16 am

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by konsumer » Thu Jan 07, 2010 1:52 pm

I've got an image with 4 columns and 3 rows (in attached love file)

I want to use the top row of sprites for facing different directions, and the 2+3 rows for walking animations.

I have got the directional stuff working, but it won't switch to "walking" mode.

I think the reason is that I am seeking on every update(). I could make it check if it needs to seek, but then it would not loop back to the right start frame. Is there a better way? I really like having all these frames in one file. It would be neat if I could actually use a really big file for all my characters, and clearFrames() then add just the Quads (maybe a convenience function, so I can just call by sprite-cell coordinates, rather then pixel) for the animation at hand. I am thinking about modifying AnAL, for my game, to do this. Does this seem like a sensible approach, or am I just misunderstanding it's functionality?
Attachments
anim_help.love
(4.84 KiB) Downloaded 238 times

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Animations And LÖVE (AnAL) - The animations replacement lib

Post by bartbes » Thu Jan 07, 2010 2:45 pm

Well, I got a basic fix for you, you need to define a step and steptime variable in love.load, step defaulting to 1 and steptime to 0, then use this love.update function:

Code: Select all

function love.update(dt)	
	if walking then
		anim:seek(step*4+direction)
		steptime = steptime + dt
		if steptime >= 0.25 then --change this
			step = (step%2)+1
			steptime = steptime - 0.25 --and this
			--if you want another delay
		end
	else
		anim:seek(direction)
	end
end
I marked the constants you need to change for another delay, 0.1 seemed a bit fast, so I used 0.25. (which seems a bit slow, though, you're going to need to finetune a bit)

EDIT: Though I should note you're relying on the quads more than on the animations (as you're not really using the animations here)

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests