Jump to content
  • Advertisement
Sign in to follow this  
DominicHughes

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

This topic is 2497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 it from disappearing

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


Thanks in Advance

Share this post


Link to post
Share on other sites
Advertisement
I understand your logic, but I don't understand how your code is structured. Is this all code in a single function? Is it the timer declaration somewhere else as a global variable and the code starting from "timer++"in a function?

Share this post


Link to post
Share on other sites
Why are you adding +1 to timer if it isn't within a function like main() or update()? It doesn't make sense to update timer without those.

As far as your code goes, I guess you are simply doing this as a test and that is why you aren't doing this in an OOP friendly manner and also why your code isn't structured in any refined way -- so, basically you just loop through all three of the images and then, reaching the final one, reset to the first one? But does it do this multiple times? Or is it just the one time (as you indicated by saying: "timer++ not in a function" meaning nothing of this is in a function being continuously updated)?

Finally, what is the image you are looping through? Where are EnemyRect and StorageRect defined? Lots and lots missing here to take any wild guesses, and I'm too tired honestly to try and figure out what it could be without more info about how the rest of your program is built.

Share this post


Link to post
Share on other sites
The main while loop of the program contains these 3 things

1).logic
2.) draw
3.)update

the rects are declared in cpp files ofc

and timer++; is just how it looks in the code I showed


The Image is a png file loaded onto a sdl_Surface

what more do you wanna know?

Share this post


Link to post
Share on other sites

what more do you wanna know?


Post code? For instance, what's stopping you from using this:
int timer = 0;

...

FRAME = timer = (timer + 1) % 4;

Without seeing more than these lines, I can't provide any help; I can't even be sure the problem lies in the lines that you posted.

Share this post


Link to post
Share on other sites
sorry to hear that Ectara but the idea would be to figure out what the common causes of the problem are wouldn't it? I'm no expert so can't really say

but heres the source code

http://pastebin.com/McJdnZRR

this is just the cpp file where the problem lies

I have changed from using if statements to using switch statements for the enemy1 timer which is where the problem lies smile.png which is on line 338 +

Share this post


Link to post
Share on other sites

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 it from disappearing

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


Thanks in Advance


Wow, that's not the prettiest code I've ever seen. You need to learn how to use functions and structures, as I suggested before. It will make things much easier for you.

How is OrangeGhostKnightSurf defined? is OrangeGhostKnightSurf[0]...[5] all setup with images?

Share this post


Link to post
Share on other sites
This is how the code looks


//SurfaceStorage.h
SDL_Surface *OrangeGhostKnightSurf[5];


//main.cpp
//////////////////
//Enemy Loading
/////////////////
OrangeGhostKnightSurf[0] = IMG_Load("ArtWork/Enemys/Idle Frame 0.png");
OrangeGhostKnightSurf[1] = IMG_Load("ArtWork/Enemys/Idle Frame 1.png");
OrangeGhostKnightSurf[2]= IMG_Load("ArtWork/Enemys/Idle Frame 2.png");
OrangeGhostKnightSurf[3] = IMG_Load("ArtWork/Enemys/Idle Frame 3.png");
OrangeGhostKnightSurf[4]= IMG_Load("ArtWork/Enemys/Idle Frame 4.png");
OrangeGhostKnightSurf[5] = IMG_Load("ArtWork/Enemys/Idle Frame 5.png");

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!