|
Timing Animation January 16, 2009 12:01AM | Registered: 17 years ago Posts: 21 |
|
Re: Timing Animation January 16, 2009 08:00AM | Registered: 17 years ago Posts: 703 |
|
Re: Timing Animation January 16, 2009 08:16AM | Registered: 17 years ago Posts: 265 |
|
Re: Timing Animation January 16, 2009 03:18PM | Registered: 17 years ago Posts: 21 |
|
Re: Timing Animation January 16, 2009 06:52PM | Registered: 17 years ago Posts: 152 |
|
Re: Timing Animation January 16, 2009 06:56PM | Registered: 17 years ago Posts: 703 |
struct animation_frames
{
xRECT m_GraphicSource;
//has a whole bunch of other stuff that you'll not need here
};
struct animations
{
animations()
{
m_pframes_graphics = NULL;
freeze = false;
lastframe = get_tick_count();
};
~animations()
{
if (m_pframes_graphics) {
delete [] m_pframes_graphics;
m_pframes_graphics =NULL;
}
};
void SetNumberOfFrames(int num) {
frames = num;
m_pframes_graphics = new animation_frames[frames];
};
void SetSource(int frame, int x, int y, int width, int height) {
m_pframes_graphics[frame].m_GraphicSource.top = y;
m_pframes_graphics[frame].m_GraphicSource.left = x;
m_pframes_graphics[frame].m_GraphicSource.right = width;
m_pframes_graphics[frame].m_GraphicSource.bottom = height;
};
int frames;
float time;
bool repeat;
bool freeze;
Uint64 lastframe;
animation_frames* m_pframes_graphics;
};
#define MAX_ANIMATIONS (10)
#define FRAME_TIME (30) // in ms
animations animeng[MAX_ANIMATIONS];
int current_animation = 0;
int current_frame = 0;
//settting everything up
animeng[0].SetNumberOfFrames(2); //set number of frame for animation
animeng[0].SetSource(0, 0,0,64,60); //frame and source on the image (x,y,w,h)
animeng[0].SetSource(1, 65,0,64,60); //frame and source on the image (x,y,w,h)
animeng[0].time = 3; // time of animation ... basically a count
animeng[1].SetNumberOfFrames ....... // and so on
Uint64 get_tick_count()
{
const Uint64 ticks = gettime();
const Uint64 ms = ticks / TB_TIMER_CLOCK;
return ms;
}
// Update code
void update()
{
Uint64 dwTime = get_tick_count(); // timer function returns the tick count
if ((dwTime - animeng[current_animation].lastframe) > (animeng[current_animation].time * FRAME_TIME))
{
animeng[current_animation].lastframe = get_tick_count();
current_frame++; // next frame
//animation time reached .... either move onto next animation or set to start.
}
}
//drawing
void draw()
{
//blit to screen based on current animation (current_animation) and current frame of that animation
...your source rect would be
animeng[current_animation].m_pframes_graphics[current_frame].m_GraphicSource.top;
animeng[current_animation].m_pframes_graphics[current_frame].m_GraphicSource.left;
animeng[current_animation].m_pframes_graphics[current_frame].m_GraphicSource.right;
animeng[current_animation].m_pframes_graphics[current_frame].m_GraphicSource.bottom;
}
void main()
{
while(gameloop)
{
update();
draw();
}
}