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

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

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:

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.
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

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?
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

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
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

Can you confirm changing lines 49 and 50 to say (i-1) instead of i fixes the problem?
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

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.
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

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

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

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.
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

Bug and fix confirmed, new version!
konsumer
Prole
Posts: 7
Joined: Wed Jan 06, 2010 5:16 am

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

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
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

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)

Who is online

Users browsing this forum: No registered users and 21 guests