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

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

Post by kikito »

There you go. I've touched mostly player.lua, but I had to change startscreen.lua a bit because you were loading images from the disk on each frame and that made the thing crash.

Notice that the animations "move up and down". That's because your frames aren't exactly aligned at the 75px height.
Attachments
helpme.love
(22.08 KiB) Downloaded 116 times
When I write def I mean function.
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 »

When you're a complete newb, the anim8 stuff doesn't make sense at all.
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. suck. Really. Badly.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito »

What is the first line you don't understand?
When I write def I mean function.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

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

Post by Puzzlem00n »

Some advice to you, Kasperelo:
  • A- If you stop telling yourself you're awful at this, you stop being awful. Basically, this is because by telling yourself you're good, you start to have the confidence to go through programming and understand it inside and out.
    B- This one might seem bad at first, but just trust me. You don't need to understand everything and how it works, you just need to understand what it does. This can be stretched to the point of completely copying something from a tutorial and using it despite no understanding of how it works. Sounds dumb, right? Well, basically, what I find is that after you use this thing you're copying enough, you naturally start to get it, and you learn how to program it yourself. Believe me, I learned a lot that way. ( Of course, that isn't to say copy an entire game, but you get that. )
    C- Don't try and learn things until you need to do them. I'm sure you, like me, have tried to look around for programming examples and been frustrated by the complexity of it. Well, after a while of doing that, I realized that I shouldn't be doing that unless I needed to learn it for my project. You may have been following this one already, but I thought I'd throw it in in case.
Now, I could wait for you to say exactly what you don't get here, but hey, I have time, so I'll just go through everything.

Code: Select all

local grid = anim8.newGrid(tileWidth, tileHeight, sheet:getWidth(), sheet:getHeight())
Alright, so here, we're creating a grid in anim8 to hold all the quads. Anim8 needs to know:
anim8.newGrid(frameWidth, frameHeight, imageWidth, imageHeight)
So, first, we have to put in the width of each quad, which you have as 35 pixels. So we take our tileWidth variable, 35. We do the same for tileHeight, 75, putting it in the next argument. Then, we need to put in the dimensions of your whole picture. We use love's built in functions to get the width and height of the sheet variable that holds the picture and put them in. If we wanted to, we could just code this:

Code: Select all

local grid = anim8.newGrid(35, 75, 140, 300)
But we're programmers, and we despise hard-coding (that means putting the numbers in without variables) so I suggest you use what Kikito gave you.

Now, how does this next part work?

Code: Select all

animations = {
    down  = anim8.newAnimation('loop', grid('1,1-4'), 0.2),
    up    = anim8.newAnimation('loop', grid('2,1-4'), 0.2),
    left  = anim8.newAnimation('loop', grid('3,1-4'), 0.2),
    right = anim8.newAnimation('loop', grid('4,1-4'), 0.2)
  }
Well, to create an animation, anim8 needs to know:
anim8.newAnimation(mode, frames, delay)
So, I'll use the "down" one as my example. When we create the new animation, we must set the mode. We choose 'loop', which will play it over and over like we want. Then, we must tell what frames to use in the animation. Now, we already have a grid we made above we can visualize like this:

Image

There are numbers marking the grid. Now, to find the frames walk down, we can look and see this chart. The character in column one is walking down. He does it in rows 1-4. Hence, we use "grid('1,1-4')" for our second argument. Now, for the last one, delay, we just need to think how many times the animation should move forward per second. 5 times a second sounds good. So, one second per 5 images is 1/5, which equals 0.2. So, we can put this together for

Code: Select all

down  = anim8.newAnimation('loop', grid('1,1-4'), 0.2)
We do the same thing for other animations.

Now, in the key movement code, we set the direction that helps us pick through these animations depending on the last key pressed. To update the right animation, we use

Code: Select all

player.animations[player.direction]:update(dt)
Which is the same as saying

Code: Select all

player.animations.down:update(dt)
if we're moving down.

We use the same basic idea for drawing it, but with some other stuff we need to add.

Code: Select all

player.animations[player.direction]:draw(sheet, player.x, player.y)
Now we get our direction and we draw the direction's parts of the grid on sheet. Then, we draw it at the player's x and y changed by pressing WSAD.

I hope I've helped you, as I've been working on this post for roughly an hour. Don't worry, it was sort of fun for me.
I LÖVE, therefore I am.
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 »

It just keeps crashing. Please help!
Attachments
helpmenew.love
(24.28 KiB) Downloaded 98 times
monkyyy
Citizen
Posts: 52
Joined: Fri Mar 16, 2012 5:29 pm

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

Post by monkyyy »

on a forum isnt the best place to learn programing
4 pages of u talking down about urself and some encouragement is probably more time consuming and hard then a howto book or a class, love is easy but not so easy that no prior experience of debugging code is needed to jump in head first in the hope u'll make a game competely solo

my first time programming was a class that took several months w/ basic math problems but looking back i can see why they taught at a slow pase(that was boring at the time) as i learned conspects like recursive functions, good coding habits, and how to debug code quickly( and how 90% of the class can cheat off three students including me >__>) well anyway my point is, baby steps, babysteps, babysteps
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 have a book. Programming In Lua. It's kinda hard to understand.
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 »

What's wrong... I'm not using AnAl or Anim8.

Please help!





EDIT: Nobody's gonna answer.
Attachments
Direction.zip
(8.2 KiB) Downloaded 92 times
User avatar
IAsep-TrixI
Citizen
Posts: 89
Joined: Mon Aug 12, 2013 4:22 am
Location: Philippines,Asia

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

Post by IAsep-TrixI »

Kasperelo wrote:What's wrong... I'm not using AnAl or Anim8.

Please help!





EDIT: Nobody's gonna answer.
Look, I started programming love2d when I was 11, trust me it was hard learning it but I Never gave up, dont put down yourself, if you try hard enough you can do it, you must be clever enough to understand animations with quads, I once made quad animations, im too lazy to do it though so I just use seperated pictures. Here's where I learned both.

The animation video
http://www.youtube.com/watch?v=FIKS37k3MBk
the quads article
https://github.com/kikito/love-tile-tut ... and-images
one more thing, use the love2d wiki sometimes, they provide you with a lot of information .Just believe in yourself and you can do it :P
An agent of the free

check out the game I'm doing with Jkash!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests