Character with animation
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- More Ragtime
- Prole
- Posts: 10
- Joined: Sat Aug 10, 2013 1:32 am
Re: Character with animation
its telling me there is an incorrect paramiter type at line 22.
Re: Character with animation
Did you load the images correctly?
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.
Code: Select all
animation.frame0 = ('untitled.png')
animation.frame1 = ('untitled1.png')
animation.frame2 = ('untitled2.png')
Don't forget the quotations areound the path or the extension.
- More Ragtime
- Prole
- Posts: 10
- Joined: Sat Aug 10, 2013 1:32 am
Re: Character with animation
ah, i forgot to put the png extention. but now its telling me its a nil value
Re: Character with animation
Could you copy and paste the error message for me? I need more than just a shot in the dark :/
- More Ragtime
- Prole
- Posts: 10
- Joined: Sat Aug 10, 2013 1:32 am
Re: Character with animation
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'
Re: Character with animation
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.
- More Ragtime
- Prole
- Posts: 10
- Joined: Sat Aug 10, 2013 1:32 am
Re: Character with animation
thanks for all your help. http://www.mediafire.com/download/1pzyy ... mation.zip
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Character with animation
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:
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.
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
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.
- More Ragtime
- Prole
- Posts: 10
- Joined: Sat Aug 10, 2013 1:32 am
Re: Character with animation
i tried that and i got an unexpected paraimiter (nil value)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:
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.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
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.
heres the .love
http://www.mediafire.com/?0ugfom8et5c2rc0
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Character with animation
Because you're attempting to feed a table into love.graphics.draw().
Try this:
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
Who is online
Users browsing this forum: No registered users and 7 guests