Animation is a blight and I can't figure it out ! help :(

Started by
2 comments, last by swiftcoder 12 years, 2 months ago
Hello I'm trying really hard to listen to the advice some people give but I generally don't want to do it a way that requires more annoying irritation and or emotional pain so I've been doing animation in SDL using interger counters like so


int timer = 0;
timer++;
if(timer == 1)
{
FRAME= 1;
}

if(timer == 2)
{
FRAME= 2;
}

if(timer == 3)
{
FRAME= 3;
timer = 0;
}


EnemyRect = StorageRect;
SDL_BlitSurface(Enemysprite[FRAME],NULL,Screen,EnemyRect);

and the problem is that everytime the code sets the timer to 0 it causes the sprite to dissappear for a few milliseconds and then shows again and repeats

and I have no Idea how to stop that from happening

could someone please tell me how to stop this from happening in the simplest and easiest way possible that doesn't require irritation


Thanks in Advance
Advertisement
okay I don't know SDL but I can instantly see a problem,
if FRAME is always equal to timer or always relative to timer,
why not

FRAME = timer?

// or better yet //

FRAME++;


gets rid of the silly if statements.
even if the if statements are needed it'd look cleaner to use a switch statement

switch (timer)
{
case(0) : {FRAME = 0;} break;
case(1) : {FRAME = 1;} break;
case(2) : {FRAME = 2;} break;
// etc. etc. //
}
Thanks for the tip :D
Closed as duplicate. Continue discussion in the more active thread.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement