## Animations

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Anxiety
Prole
Posts: 49
Joined: Sat Apr 02, 2011 9:36 am
Location: Finland

### Animations

How can i make simple image animations without having to use a loop to show different images at an order?

Thanks!
I can't come up with a good signature!

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: Animations

Actually, in most cases you don't need a loop. The basis of animation is changing an image on every love.update() call:

Code: Select all

  love.load()
animation = {
}
frame = 1 -- loops from 1 to 3
timepassed = 0 -- how much time has passed since the last frame
end

love.update(dt)
timepassed = timepassed + dt
if timepassed >= 0.5 then
timepassed = 0
frame = frame + 1
if frame == 4 then frame = 0 end
end
end

love.draw()
love.graphics.draw(animation[frame], 100, 200)
end

I've tried to keep the code as simple as possible. You may notice that there are no loops.

Here are some things you should take into account:
• once you are familiar with images and you have a working example, give a look at Quads. They are faster and more appropriate to animation-related stuff
• Bartbe's AnAL lib simplifies this work a lot. Spend some time learning it.
When I write def I mean function.

### Who is online

Users browsing this forum: No registered users and 26 guests