![]() |
|
Slowing down animation |
dothedru22
Member #7,325
June 2006
|
I've searched and searched this forum, gamedev and other language forums(blitz, dark basic, etc) without a really specific answer. How would I go about slowing animation of a character. Like I got the the fps limiting to 30 fps but the frames of the actual character are still to fast. I don't care what language you write it in(although C would be best). I just need some logic or the actual code. thanks for any help. right now i have something like this.
the code is called in a while loop in main.c |
23yrold3yrold
Member #1,134
March 2001
![]() |
Keyframes, my friend. Keyframes. -- |
Jonny Cook
Member #4,055
November 2003
|
You should be using some kind of animation structure. Each frame should have it's own delay. Maybe something like this.
Something like that. If you want more control over your animation, you can have an array of delays (a separate delay for each individual frame). The face of a child can say it all, especially the mouth part of the face. |
dothedru22
Member #7,325
June 2006
|
hey thanks for the replies so fast. i like the idea you had Johnny. I had tried something sortof of the same concept earlier without much luck. It definatly works its just that the frames are really choppy. I feel that when im doing that all im doing is creating a rest function. Its almost the same thing. But I appreciate the help so fast. |
23yrold3yrold
Member #1,134
March 2001
![]() |
Quote: Each frame should have it's own delay.
Yeah, that's what I meant by 'keyframe'; I should have elaborated. -- |
Jonny Cook
Member #4,055
November 2003
|
Quote: I feel that when im doing that all im doing is creating a rest function. Its almost the same thing. Almost, but not quite. With rest, the program exectution stops until rest returns. This would cause your game to appear to be laggy, which you certainly do not want. I've used this method many times before (I believe it's quite standard), so it should work for you. The face of a child can say it all, especially the mouth part of the face. |
dothedru22
Member #7,325
June 2006
|
hmm well maybe its my implementation of it or something. i changed mine to the way you did yours. heres what i have
|
Kitty Cat
Member #2,815
October 2002
![]() |
Your createPlayer function is creating a memory leak, and your deletePlayer function is bugged. When you allocate something, you need to keep a pointer to it around so you can free it later. When you return *player, you're basically just copying out the data and getting rid of the pointer. And when calling deletePlayer, I assume you're using like you did before (ie. deletePlayer(&something_on_the_stack);), meaning it's trying to free memory it can't. -- |
dothedru22
Member #7,325
June 2006
|
so like i need a pointer to a function? |
Steve Terry
Member #1,989
March 2002
![]() |
Either update using floats (i.e. a number less than 1) or use a timer and keep a delay variable with each object. ___________________________________ |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: so like i need a pointer to a function? No. You need a pointer to an object. struct S_Player *player = createPlayer(); ... destroyPlayer(player); player = NULL;
-- |
dothedru22
Member #7,325
June 2006
|
Quote: Either update using floats (i.e. a number less than 1) thats a good idea. thanks. it works but i have obviously type cast the array index to a integer every looop. not sure if this will cause major slow down in the long run. or if using a float in generals gonna cause much problem. Quote: No. You need a pointer to an object. struct S_Player *player = createPlayer(); not sure what your saying. isnt that what i already have. |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: not sure what your saying. isnt that what i already have. No, because createPlayer doesn't return a pointer. I can't say for 100% certainty what you're doing though because you haven't showed the code since you updated the code. But if you have: struct S_Player player = createPlayer(); ... destroyPlayer(&player); Then you have a memory leak, still have the player object on the stack, and try to free stack memory (all very bad). -- |
dothedru22
Member #7,325
June 2006
|
oh i see. thanks man. i get a message saying i cant do that. says something like imcompatable types. |
Kitty Cat
Member #2,815
October 2002
![]() |
Because createPlayer isn't returning a pointer. You need to make it return struct S_Player* instead of struct S_Player. -- |
dothedru22
Member #7,325
June 2006
|
i thought that was sortof what i was doig when i said return *player. im sorry just not getting it. i've tried a bunch of ways. |
Kitty Cat
Member #2,815
October 2002
![]() |
return *player; means you're deferencing the player pointer, and copying it to the object you're setting in main(). return player; will copy the pointer value (which is what you want), but you have to define the function to return a pointer, and set a pointer in main(). eg: struct S_Player *createPlayer(void) { struct S_Player *player = malloc(sizeof(struct S_Player)); ... return player; } int main() { ... struct S_Player *player = createPlayer(); ... destroyPlayer(player); player = NULL; ... }
-- |
dothedru22
Member #7,325
June 2006
|
oh i see man. not sure the theory behind it. but it works now. hopefully this weekend i'll read up on this more. i thought i knew the language pretty well but i guess not. i appreicate your help so fast. |
Neil Walker
Member #210
April 2000
![]() |
If you need any further information/examples on coding your animations, download and check out the code for the animation part of my library mentioned in my sig. all the code is handled in the method, 'nextframe'. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Matt Kindy
Member #7,331
June 2006
![]() |
If all else fails, you could play the same frame twice, effectively cutting the FPS in half shrugs |
Jonny Cook
Member #4,055
November 2003
|
That's exactly what a frame delay accomplishes. The face of a child can say it all, especially the mouth part of the face. |
|