Page 1 of 1

Animation update error

Posted: Mon Aug 17, 2009 3:18 pm
by zugamifk
Oh god, I don't know why this is happening but it's driving me insane.
i have loaded a bunch of character animations for my game into a table like this:

Code: Select all

images = {
	world = {
		player = {
			idle = {
				down = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/idle_down.png" ), 25, 50, 0.1),
				up = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/idle_up.png" ), 25, 50, 0.1),
				right = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/idle_right.png" ), 25, 50, 0.1),
				left = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/idle_left.png" ), 25, 50, 0.1),
			},
			walk = {
				right = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/walk_right.png" ), 25, 50, 0.1),
				left = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/walk_left.png" ), 25, 50, 0.1),
				up = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/walk_up.png" ), 25, 50, 0.1),
				down = love.graphics.newAnimation(love.graphics.newImage( "tiles/character/walk_down.png" ), 25, 50, 0.1),
			},
	},
}

And I update my animations thusly:

Code: Select all

images.world.player[self.state][self.facing]:update(dt)
Where [self.state] is a string that with the values or either "idle" or "walk and [self.facing] has "up, "down".. etc.

But it doesn't work. I get this error "Error in update (arg 2), expected 'float' got 'nil'"
And it's directed at the line with the animation update. I've used animations before and so I
m baffled as to what's causing this. The only differences right now is that I have all of my images loaded into a series of tables, and I update my animations with a player:draw() method instead of in the main draw() function, although I get the same error if I try it there.

Can someone perhaps provide some insight for me? I'm completely lost.

Re: Animation update error

Posted: Mon Aug 17, 2009 3:53 pm
by bartbes
It seems like it can't detect the "self" parameter, which happens mostly when you forget to use :, however, since you use it, that can't be the problem. And, because it detects that that is in the right format, I think the problem is dt == nil in your code. Check if the update function is declared with dt, and if it's still valid in the piece of code where you call it, if you somehow can't get it back, use love.timer.getDelta() instead of dt.

Re: Animation update error

Posted: Mon Aug 17, 2009 4:24 pm
by zugamifk
love.timer.getDelta() did it, thank you. I wonder, why would I need to do this for my current game but not for my last one?

Re: Animation update error

Posted: Mon Aug 17, 2009 4:40 pm
by bartbes
Because dt isn't declared where you are, thus equals nil. Is it possible you do this in draw? Or renamed the argument to the update callback?

Re: Animation update error

Posted: Tue Aug 18, 2009 3:45 pm
by qubodup
zugamifk wrote:love.timer.getDelta() did it, thank you. I wonder, why would I need to do this for my current game but not for my last one?
maybe you used function update(dt) in the last game but did not use the dt in this one?