Character with animation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
More Ragtime
Prole
Posts: 10
Joined: Sat Aug 10, 2013 1:32 am

Re: Character with animation

Post by More Ragtime »

its telling me there is an incorrect paramiter type at line 22.
User avatar
borix134
Prole
Posts: 18
Joined: Sat Aug 10, 2013 5:37 am

Re: Character with animation

Post by borix134 »

Did you load the images correctly?

Code: Select all

animation.frame0 = ('untitled.png')
animation.frame1 = ('untitled1.png')
animation.frame2 = ('untitled2.png')
Those aren't images. Type in the path to the images of the animation.
Don't forget the quotations areound the path or the extension.
User avatar
More Ragtime
Prole
Posts: 10
Joined: Sat Aug 10, 2013 1:32 am

Re: Character with animation

Post by More Ragtime »

ah, i forgot to put the png extention. but now its telling me its a nil value
User avatar
borix134
Prole
Posts: 18
Joined: Sat Aug 10, 2013 5:37 am

Re: Character with animation

Post by borix134 »

Could you copy and paste the error message for me? I need more than just a shot in the dark :/
User avatar
More Ragtime
Prole
Posts: 10
Joined: Sat Aug 10, 2013 1:32 am

Re: Character with animation

Post by More Ragtime »

yeah sorry, it says

Code: Select all

Error
main.lua:4: attempt to index global 'Untitled' (a nil value)

Traceback

main.lua:4: in function 'load'
[C]: in function 'xpcall'
User avatar
borix134
Prole
Posts: 18
Joined: Sat Aug 10, 2013 5:37 am

Re: Character with animation

Post by borix134 »

No biggie. This is pretty odd. My only guess would be maybe you don't have the images in the same directory as the main.lua. If that dosen't work then maybe you could upload a .love file so I could fix it up.
User avatar
More Ragtime
Prole
Posts: 10
Joined: Sat Aug 10, 2013 1:32 am

Re: Character with animation

Post by More Ragtime »

User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: Character with animation

Post by DaedalusYoung »

There are several ways to do it. If your going to put the animation frames in a table, then at least just do it like:

Code: Select all

love.load()
  animation = {}
  animation[1] = love.graphics.newImage('anim1.png')
  animation[2] = love.graphics.newImage('anim2.png')
  animation[3] = love.graphics.newImage('anim3.png')
end
So you can easily loop through the frames without having to do the weird if frame == 1 then ... elseif frame == 2 then ... elseif frame == 3 then ... end loop, just doesn't make sense.

Another way to do it is to put all your frames in a texture atlas / sprite sheet and use a quad to display the frames, then just keep changing the quad's coordinates to change the displayed frame. I would prefer this method, to be honest.
User avatar
More Ragtime
Prole
Posts: 10
Joined: Sat Aug 10, 2013 1:32 am

Re: Character with animation

Post by More Ragtime »

DaedalusYoung wrote:There are several ways to do it. If your going to put the animation frames in a table, then at least just do it like:

Code: Select all

love.load()
  animation = {}
  animation[1] = love.graphics.newImage('anim1.png')
  animation[2] = love.graphics.newImage('anim2.png')
  animation[3] = love.graphics.newImage('anim3.png')
end
So you can easily loop through the frames without having to do the weird if frame == 1 then ... elseif frame == 2 then ... elseif frame == 3 then ... end loop, just doesn't make sense.

Another way to do it is to put all your frames in a texture atlas / sprite sheet and use a quad to display the frames, then just keep changing the quad's coordinates to change the displayed frame. I would prefer this method, to be honest.
i tried that and i got an unexpected paraimiter (nil value)
heres the .love
http://www.mediafire.com/?0ugfom8et5c2rc0
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: Character with animation

Post by DaedalusYoung »

Because you're attempting to feed a table into love.graphics.draw().

Try this:

Code: Select all

function love.load()
	animation = {}
	animation[1] = love.graphics.newImage('Untitled.png')
	animation[2] = love.graphics.newImage('Untitled2.png')
	animation[3] = love.graphics.newImage('Untitled3.png')
	counter = 0
	frame = 1
end

function love.update(dt)
 	counter = counter + dt
 	if counter >= 0.2 then
 		counter = 0
 		frame = frame + 1
 		if frame == 4 then
 			frame = 1
 		end
 	end
	if love.keyboard.isDown("d") then
		x = x + (speed * dt)
	elseif love.keyboard.isDown("a") then
		x = x - (speed * dt)
	end
	if love.keyboard.isDown("s") then
		y = y + (speed * dt)
	elseif love.keyboard.isDown("w") then
		y = y - (speed * dt)
	end
end

function love.draw()
	love.graphics.draw(animation[frame], 0,  0)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], slime and 58 guests