Animation update error

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
zugamifk
Prole
Posts: 28
Joined: Sun Jul 26, 2009 4:01 pm

Animation update error

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Animation update error

Post 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.
User avatar
zugamifk
Prole
Posts: 28
Joined: Sun Jul 26, 2009 4:01 pm

Re: Animation update error

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Animation update error

Post 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?
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Animation update error

Post 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?
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests