Using Loop to animate Sprites

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
sabino
Prole
Posts: 4
Joined: Thu Jun 19, 2014 4:10 pm

Using Loop to animate Sprites

Post 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:
User avatar
bdjnk
Citizen
Posts: 81
Joined: Wed Jul 03, 2013 11:44 pm

Re: Using Loop to animate Sprites

Post 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).
User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

Re: Using Loop to animate Sprites

Post 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
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Using Loop to animate Sprites

Post 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.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests