How can i make simple image animations without having to use a loop to show different images at an order?
Thanks!
Animations
Animations
I can't come up with a good signature!
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- 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:
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:
Code: Select all
love.load()
animation = {
love.graphics.load('image1.png'),
love.graphics.load('image2.png'),
love.graphics.load('image3.png')
}
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
Here are some things you should take into account:
When I write def I mean function.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests