[SOLVED]Animation!

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Arclord
Prole
Posts: 6
Joined: Tue Nov 01, 2011 8:41 pm

[SOLVED]Animation!

Post by Arclord »

Hi,
Is there anyway to create animation from a sequence of single images rather than spritesheet?

Thanks in advance.
Regards.
Last edited by Arclord on Thu Nov 03, 2011 7:39 pm, edited 1 time in total.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Animation!

Post 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.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Animation!

Post 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
Arclord
Prole
Posts: 6
Joined: Tue Nov 01, 2011 8:41 pm

Re: Animation!

Post by Arclord »

It says - attempt to call table value.

Thanks for the reply.
Regards.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Animation!

Post 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.
Arclord
Prole
Posts: 6
Joined: Tue Nov 01, 2011 8:41 pm

Re: Animation!

Post by Arclord »

Sorry, I forgot to post the love file. Here it is.

EDIT: attachment removed.

Thanks
Last edited by Arclord on Thu Nov 03, 2011 7:39 pm, edited 1 time in total.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Animation!

Post 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.
Arclord
Prole
Posts: 6
Joined: Tue Nov 01, 2011 8:41 pm

Re: Animation!

Post by Arclord »

Yes. got it. Thanks T-Bone for your time and help.

Regards.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests