1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
SDL_Surface* explosion;
class animation{
private:
bool status;
int xpos, ypos, frame, length;
SDL_Surface* image; commented out
SDL_Rect rect;
public:
animation(int x, int y, int w, int h, SDL_Surface* im, int l);
int getframe();
void printimage();
void animate();
};
animation::animation(int x, int y, int w, int h, SDL_Surface* im, int l){
status = true;
frame = -1;
xpos = x;
ypos = y;
rect.x = 0; rect.y = 0; rect.w = w; rect.h = h;
image = im;
length = l;
}
void animation::printimage(){
apply_surface(xpos, ypos, explosion, screen, &rect);//now apply_surface works fine using a surface defined outside the class.
}
void animation::animate(){
if (status == false) return;
if (frame > length) status = false;
frame += 1;
rect.x = rect.w*frame;
printimage();
}
|