Page 2 of 8

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

Posted: Sat Sep 19, 2009 2:59 pm
by nevon
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.

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

Posted: Sat Sep 19, 2009 4:17 pm
by bartbes
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?

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

Posted: Sat Sep 19, 2009 4:31 pm
by nevon
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.

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

Posted: Sat Sep 19, 2009 5:03 pm
by bartbes
Can you confirm changing lines 49 and 50 to say (i-1) instead of i fixes the problem?

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

Posted: Sat Sep 19, 2009 5:16 pm
by nevon
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.

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

Posted: Sat Sep 19, 2009 5:21 pm
by bartbes
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

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

Posted: Sat Sep 19, 2009 5:26 pm
by nevon
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:

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

Posted: Sat Sep 19, 2009 5:31 pm
by bartbes
Bug and fix confirmed, new version!

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

Posted: Thu Jan 07, 2010 1:52 pm
by konsumer
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?

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

Posted: Thu Jan 07, 2010 2:45 pm
by bartbes
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)