Hi,
I've a problem with sprite animation. I use the idea of the cone3d tutorial.
but the frame runs without any smoothness (what is the contrary?sorry my english:).
I clean the code to test the draw fuction, look like this..
class Ssprite {
SDL_Rect pos;
vector<SDL_Surface*> tiles;
SDL_Surface* screen;
int currFrame;
int lastTicks; //for animation
public:
Ssprite(const char*,SDL_Surface*);
void Draw();
};
void Ssprite::Draw(){
if(lastTicks + PAUSE < SDL_GetTicks()){
currFrame++;
if(currFrame > 4)
currFrame=0;
SDL_BlitSurface(tiles[currFrame],0,screen,&pos);
}
lastTicks = SDL_GetTicks();
}
With PAUSE = 1 or PAUSE = 2
run very fast at start but with 3 or up it runs without any smoothness.
with PAUSE = 5 freeze on some frame for about 1 sec before change frame!!
This is the main:
int main ( int argc, char** argv )
{
// initialize SDL video
if ( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
atexit(SDL_Quit);
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32,
SDL_HWSURFACE|SDL_DOUBLEBUF);
Ssprite player("",screen);
bool done = false;
while (!done)
player.Draw();
SDL_Flip(screen);
}
printf("Exited cleanly\n");
return 0;
}
I've clened the code a bit for better reading
I can't figure out what i'm doing wrong.
I'm devving on debian linux with Code::Blocks.
Thanks
Garulf-
PS: what's the tag to show the code in a scrolling frame?