Dynamic Animation?
Posted: Mon Mar 30, 2009 8:56 pm
I'm just curious how everyone else here handles animation in their games? I know plenty of ways to hard code animation and tile sheet clips, but I'm trying to create something a little more dynamic. Not every animation will have the same number of frames, or do the same thing (ie. a character will have walking animations, maybe attacking animations, whereas water might just have 2 or 3 frames).
Ultimately characters will be created from a Lua script, so I want something that will allow the scripter to pass a filename, the number of frames, what frames are used for what or something like that (I don't need code for binding Lua, I know how to do this and I'll handle it later).
The only other way I could think of to do this, would be to handle animation from the actual Lua script, where the scripter would use input (ie. left arrow key) and then call character:setframe(int frame) themselves.. maybe?
This is my pseudo class that I was messing around with for ideas:
How do you guys handle this? Feel free to post anything you feel is relevant. I've never really done anything other than hard coded sprite clipping and animation, so if my attempts are way off point it out please.
EDIT: Also, this is sort of an abstract future reference question, but I will eventually need to store some sort of animated tile data, so if you have recommendations as to how you store animations in your level files that would be helpful too.
Ultimately characters will be created from a Lua script, so I want something that will allow the scripter to pass a filename, the number of frames, what frames are used for what or something like that (I don't need code for binding Lua, I know how to do this and I'll handle it later).
The only other way I could think of to do this, would be to handle animation from the actual Lua script, where the scripter would use input (ie. left arrow key) and then call character:setframe(int frame) themselves.. maybe?
This is my pseudo class that I was messing around with for ideas:
Code: Select all
#ifndef CHARACTER_H_INCLUDED
#define CHARACTER_H_INCLUDED
struct Animation{
public:
std::string name;
int startindex;
int frames;
};
class Character{
private:
std::string name;
int x;
int y;
int w;
int h;
int frame;
//slightly more dynamic approach, merely pseudocode
std::vector<Animation> animData;
//hard coded variables for each direction
//int rightanimstart;
//int rightanimframes;
//int leftanimstart;
//int leftanimframes;
//int downanimstart;
//int downanimframes;
//int upanimstart;
//int upanimframes;
int surface;
public:
Character( std::string filename );
~Character();
//current function user just sets x and y coords for a single image
void Move( int newx, int newy );
int Draw();
};
#endif // CHARACTER_H_INCLUDED
EDIT: Also, this is sort of an abstract future reference question, but I will eventually need to store some sort of animated tile data, so if you have recommendations as to how you store animations in your level files that would be helpful too.