Page 1 of 1
Animate images?
Posted: Thu Nov 24, 2011 6:07 pm
by kurtss
So I have my code here:
http://codepad.org/fIKaTf5P
Say I wanted to animate the second and third sprites in the following image:
- ivQKu.png (1.45 KiB) Viewed 326 times
How would I go about doing that?
Thanks in advance!
Re: Animate images?
Posted: Thu Nov 24, 2011 6:38 pm
by Taehl
You could write some code which watches the time and switches quads appropriately. But it's already been done for you - most lovers enjoy
AnAL.
Re: Animate images?
Posted: Thu Nov 24, 2011 6:52 pm
by Ellohir
You can create a variable like "current_sprite" and change it from walking to jumping as you need.
on love.load()
Code: Select all
player.current_sprite = player.standing
on love.update()
Code: Select all
if player.y_velocity ~= 0 then
player.current_sprite = player.walking
...
else
player.current_sprite = player.standing
on love.draw()
Code: Select all
love.graphics.drawq(player.sprite, player.current_sprite, player.x, player.y)
As Taehl said, for walking you can use timers. But I prefer having a "player.walked" meter what changes the sprite along some distance and then resets the counter when the cycle ends.
Anyway, I have tried your code and it's great. The player has a very smooth movement, I liked it a lot, congratulations
Re: Animate images?
Posted: Thu Nov 24, 2011 7:10 pm
by kurtss
Thanks to you both! I'll try AnAL. (Sounds so wrong, I love it!)
Re: Animate images?
Posted: Thu Nov 24, 2011 8:07 pm
by T-Bone
As already mentioned, there are plenty of different ways to do it. If you're a beginner, I'd recommend doing something simple by yourself just for the practise. It's really not that hard.