Need help with animation/quads, please help!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- 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!
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.
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.
Re: Need help with animation/quads, please help!
When you're a complete newb, the anim8 stuff doesn't make sense at all.
Re: Need help with animation/quads, please help!
I. suck. Really. Badly.
- 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!
What is the first line you don't understand?
When I write def I mean function.
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Need help with animation/quads, please help!
Some advice to you, Kasperelo:
Alright, so here, we're creating a grid in anim8 to hold all the quads. Anim8 needs to know:
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?
Well, to create an animation, anim8 needs to know:
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
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
Which is the same as saying
if we're moving down.
We use the same basic idea for drawing it, but with some other stuff we need to add.
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.
- 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.
Code: Select all
local grid = anim8.newGrid(tileWidth, tileHeight, sheet:getWidth(), sheet:getHeight())
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:anim8.newGrid(frameWidth, frameHeight, imageWidth, imageHeight)
Code: Select all
local grid = anim8.newGrid(35, 75, 140, 300)
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)
}
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:anim8.newAnimation(mode, frames, delay)
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)
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)
Code: Select all
player.animations.down:update(dt)
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)
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.
Re: Need help with animation/quads, please help!
It just keeps crashing. Please help!
- Attachments
-
- helpmenew.love
- (24.28 KiB) Downloaded 98 times
Re: Need help with animation/quads, please help!
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
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
Re: Need help with animation/quads, please help!
I have a book. Programming In Lua. It's kinda hard to understand.
Re: Need help with animation/quads, please help!
What's wrong... I'm not using AnAl or Anim8.
Please help!
EDIT: Nobody's gonna answer.
Please help!
EDIT: Nobody's gonna answer.
- Attachments
-
- Direction.zip
- (8.2 KiB) Downloaded 91 times
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: Need help with animation/quads, please help!
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.Kasperelo wrote:What's wrong... I'm not using AnAl or Anim8.
Please help!
EDIT: Nobody's gonna answer.
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
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests