Animate images?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
kurtss
Prole
Posts: 6
Joined: Wed Nov 23, 2011 4:37 pm

Animate images?

Post 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
ivQKu.png (1.45 KiB) Viewed 327 times
How would I go about doing that?

Thanks in advance!
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Animate images?

Post 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.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Animate images?

Post 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 ;)
kurtss
Prole
Posts: 6
Joined: Wed Nov 23, 2011 4:37 pm

Re: Animate images?

Post by kurtss »

Thanks to you both! I'll try AnAL. (Sounds so wrong, I love it!)
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Animate images?

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest