Need help with animation/quads, please help!

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.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Need help with animation/quads, please help!

Post by Jasoco »

You have your quad:

Code: Select all

your_quad = love.graphics.newQuad(x, y, w, h, your_image:getWidth(), your_image:getHeight)
You draw your quad:

Code: Select all

love.graphics.drawq(your_image, your_quad, x, y, ...)
Note the drawq, as opposed to just draw. The q means it will draw a quad instead of just an image.

Just an example. Quite simple.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Need help with animation/quads, please help!

Post by Kasperelo »

No, I mean drawing animated quads! I don't know how to animate them!
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Need help with animation/quads, please help!

Post by Jasoco »

You have an array of quads with numbers referring to frames.

You have a variable that changes at the framerate you choose and loops.

You draw the quad that corresponds to the current frame.
Last edited by Jasoco on Sat May 05, 2012 7:27 pm, edited 2 times in total.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Need help with animation/quads, please help!

Post by Kasperelo »

I don't know how to do the drawing...
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Need help with animation/quads, please help!

Post by Jasoco »

For instance, you have a sprite sheet with all your animation frames next to each other.

You create the array of quads pseudo-ically like so:

Code: Select all

quad_array = {}
for i = 1, number_of_frames do
  quad_array[i] = love.graphics.newQuad((i - 1) * frame_width, y, frame_width, frame_height, image:getWidth(), image:getHeight())
end
Then in your update function for your animated thingy you increment the frames like so:

Code: Select all

current_frame = current_frame + dt * frame_animation_speed
if current_frame > number_frames then current_frame = 1 end
Then you draw the current quad...

Code: Select all

love.graphics.drawq(image, quad_array[math.floor(current_frame)], x, y, ...)
Or something like that. It's just pseudo.

UPDATE stuff goes in love.update(dt)

DRAW stuff goes in love.draw()
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Need help with animation/quads, please help!

Post by Kasperelo »

I feel stupid.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Need help with animation/quads, please help!

Post by Jasoco »

Did it solve it? And which part was it?
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Need help with animation/quads, please help!

Post by Kasperelo »

I feel stupid. 'Cause I don't understand anything...
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Need help with animation/quads, please help!

Post by Nixola »

Then you're not stupid, you simply don't know things. Search for Kikito's tile tutorial, it taught me lua!
Kikito, did I karma you for this?
Last edited by Nixola on Sat May 05, 2012 9:05 pm, edited 1 time in total.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Need help with animation/quads, please help!

Post by Kasperelo »

Awesome!!!
Post Reply

Who is online

Users browsing this forum: 1Minus2P1Stringer2 and 2 guests