Page 1 of 1
[SOLVED]Animation!
Posted: Thu Nov 03, 2011 4:54 pm
by Arclord
Hi,
Is there anyway to create animation from a sequence of single images rather than spritesheet?
Thanks in advance.
Regards.
Re: Animation!
Posted: Thu Nov 03, 2011 5:55 pm
by Ellohir
Sure. Insted of cycling through an array of quads, shift through an array of images. Adapting from a spritesheet model should be quite simple.
Re: Animation!
Posted: Thu Nov 03, 2011 6:15 pm
by T-Bone
Just store the images you want to use in a table, and have a constant that refers to the currently displayed image. Something like this
Code: Select all
images = {}
images[1] = love.newImage(...) --add lots of images
currImage = 1 --stores the number of the current image
function draw()
love.graphics.draw(images(currImage),...)
end
function cycle()
--cycles through the different animations one step, call this every once in a while
currImage = currImage + 1
if currImage > #images then
currImage = 1
end
end
Re: Animation!
Posted: Thu Nov 03, 2011 6:46 pm
by Arclord
It says - attempt to call table value.
Thanks for the reply.
Regards.
Re: Animation!
Posted: Thu Nov 03, 2011 7:11 pm
by T-Bone
Arclord wrote:It says - attempt to call table value.
Thanks for the reply.
Regards.
Haha, too much MATLAB for me recently.
Code: Select all
images = {}
images[1] = love.newImage(...) --add lots of images
currImage = 1 --stores the number of the current image
function draw()
love.graphics.draw(images[currImage],...)
end
function cycle()
--cycles through the different animations one step, call this every once in a while
currImage = currImage + 1
if currImage > #images then
currImage = 1
end
end
I made a mistake. Still, this is just pseudo-code. Just use it as an example of the idea rather than copy-pasting it into your own game. If there's some part of what I'm doing you don't understand, feel free to ask.
Also, not to be a jerk, but you break the forum rules. When you ask for help, make it easier for us to help you. Most important of all, post .love-files. Saying "I get this error" doesn't make it easy to help you.
Re: Animation!
Posted: Thu Nov 03, 2011 7:22 pm
by Arclord
Sorry, I forgot to post the love file. Here it is.
EDIT: attachment removed.
Thanks
Re: Animation!
Posted: Thu Nov 03, 2011 7:27 pm
by T-Bone
Arclord wrote:Sorry, I forgot to post the love file. Here it is.
Thanks
Picking the i:th value of a table is table
, not table(i) like I wrote first.
Also, you need to call cycle every once in a while.
Re: Animation!
Posted: Thu Nov 03, 2011 7:38 pm
by Arclord
Yes. got it. Thanks T-Bone for your time and help.
Regards.