Page 1 of 1

Using Loop to animate Sprites

Posted: Tue Jul 01, 2014 4:16 pm
by sabino
Hi there,
I've just learnt how to animate sprite using love.graphics.newQuad(),
I've also read how to use a loop to animate sprites,
the example is:

for i=1,8 do
love.graphics.newQuad((i-1)*32, 0, 32, 32, 256, 32)
end

What does i=1,8 mean?
Thank you :awesome: :awesome:

Re: Using Loop to animate Sprites

Posted: Tue Jul 01, 2014 4:45 pm
by bdjnk
sabino wrote:What does i=1,8 mean?
Whenever I have a question about Lua, I visit these sites (the links take you to the relevent section on for loops):
  • The lua-users wiki (usually the most helpful, has various tips and tricks).
    The Lua Reference Manual (mostly useful if you just need a reminder or an exact technical explanation).
    And Programming in Lua (probably the easiest for beginners, but I find the style difficult to read).

Re: Using Loop to animate Sprites

Posted: Tue Jul 01, 2014 4:53 pm
by Rukiri
The easiest way to animate frames is.
Width, Height of the actual spritesheet.
Number of frames in the sprite sheet.

So say your walking "down" frames starts at frame 1 and goes to frame 5, you loop 1-5.
I swear there was documentation covering spritesheets...

Generally for loops work like this.

so say I'm checking to see if my party is less than three.

for i=1, RPG:Party<=3, i++
// Add people to meh party
end
else
print "Sorry, you have to many people in your party!"
end

Re: Using Loop to animate Sprites

Posted: Tue Jul 01, 2014 5:21 pm
by kikito
I wrote about this in my love-tile-tutorial.

Start here:

https://github.com/kikito/love-tile-tut ... c-concepts

And keep reading until you reach a chapter called "0c loops". It's explained there.

Then you can keep reading to learn more stuff if you want.