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.