You got me :), edited above post so as not to lead people the wrong way.
Heres a simple example using the Image struct and functions from the graphics.h lib from psp-programming:Zitat:
I need to know how i would go about doing some animation. Any links ?
You just have to fill in the blanks for how you wish to draw and initialise the animation, I just provided those implemetations as examples of how you could do it.Code:typedef stuct
{
Image** images; // An array of image pointers
int num_fames; // The number of elements in the above array
int current_frame; // The current frame of the animation
int anim_time; // The time counter
int frame_duration; // The duration of a single frame in milli-seconds
} Animation;
void updateAnimation( Animation* anim, int dt)
{
// add the time change in time to the counter
anim->anim_time += dt;
if( anim->anim_time > ( anim->frame_duration * ( anim->current_frame + 1)))
{
// if the anim_time exceeds the time for a single frame go to the next one
anim->current_frame++;
}
if( anim->current_frame >= anim->num_frames)
{
// if the sprite is on it's last frame return to first frame
anim->anim_time %= (anim->num_frames * anim->frame_duration);
anim->current_frame = 0;
}
}
void loadAnim( Animation* anim, int num_frames, int fps)
{
// allocate memory for the images array and load the images
// set anim->num_frames to the number of images in the anim
// set the current_frame and anim_time to 0
// set the frame_duration to the speed you require (about 200 ms looks ok)
anim->images = (Image**)malloc( sizeof(Image*) * num_frames);
int i = 0;
for ( i = 0; i < num_frames; i++)
{
char buffer[255];
sprintf( buffer, "./anim/frame%d.png", i);
anim->images[i] = loadImage( buffer);
}
anim->num_frames = num_frames;
anim->current_frame = anim->anim_time = 0;
anim->frame_duration = 1000/fps;
}
void drawAnim( Animation* anim, int x, int y)
{
// draw 'anim->images[current_frame];' however you want
// maybe blitAlphaImageToScreen( bla, bla, bla );
Image* temp = 'anim->images[current_frame];
blitAlphaImageToScreen( 0, 0, temp->imageWidth, temp->imageHeight, temp, x, y);
}
I recommend using a timer to calculate the 'dt' value for the update function but if you don't wish to then just pass it the value 16 everytime.
If you want to reset the anim, just set anim_time and current_frame to zero.
Note: I'm not guarantee'ing this will compile or work but the basic idea is there, if you attempt to understand it you will probably be able to de-bug and use it.
EDIT: Added animation stuff to avoid double post.
