View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

13 replies to this topic

#1DarkHorseKnight  Members

Posted 08 February 2012 - 02:37 PM

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

#2meeshoo  Members

Posted 08 February 2012 - 02:57 PM

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?

#3DarkHorseKnight  Members

Posted 08 February 2012 - 03:08 PM

The timer declaration is just a int timer = 0; at the top of the cpp file as simple as that and timer++ is not in a function.

#4DarklyDreaming  Members

Posted 08 February 2012 - 05:55 PM

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.
"I will personally burn everything I've made to the fucking ground if I think I can catch them in the flames."
~ Gabe

"I don't mean to rush you but you are keeping two civilizations waiting!"
~ Cavil, BSG.
"If it's really important to you that other people follow your True Brace Style, it just indicates you're inexperienced. Go find something productive to do."
~ Bregma

"Well, you're not alone.

There's a club for people like that. It's called Everybody and we meet at the bar."

~ Antheus

#5DarkHorseKnight  Members

Posted 08 February 2012 - 06:02 PM

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?

#6Ectara  Members

Posted 08 February 2012 - 06:12 PM

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.

#7DarkHorseKnight  Members

Posted 08 February 2012 - 06:18 PM

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 which is on line 338 +

#8DarkHorseKnight  Members

Posted 09 February 2012 - 11:40 AM

Anyone else with some ideas?

#9BeerNutts  Members

Posted 09 February 2012 - 01:04 PM

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

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?
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#10DarkHorseKnight  Members

Posted 09 February 2012 - 02:28 PM

This is how the code looks

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

//main.cpp
//////////////////
/////////////////


#11BeerNutts  Members

Posted 09 February 2012 - 03:18 PM

SDL_Surface *OrangeGhostKnightSurf[5];

There's your problem. You only allocate 5 Surfaces elements in your array, yet you fill it with 6 (0 - 5 is 6 images). You need to define it with 6 elements:

SDL_Surface *OrangeGhostKnightSurf[6];

That will solve you immediate problem. Your bigger problem is you aren't using functions to break up your code into pieces, and you aren't using structure to group common components and their attributes. You're going to have one massive headache trying to deal with that.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#12DarkHorseKnight  Members

Posted 09 February 2012 - 03:35 PM

I'm going to be using classes/structures and functions in my next game project.

You have inspired me and thanks so much you solved my problem I can't believe how strict arrays are but thanks so much I now know to be carefull when using arrays

#13Servant of the Lord  Members

Posted 09 February 2012 - 04:11 PM

You have inspired me and thanks so much you solved my problem I can't believe how strict arrays are but thanks so much I now know to be carefull when using arrays

Which is why C++ has std::vectors.

int timer = 0;
FRAME = timer;

timer++;

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

The actual reason you never saw the first frame, is because you never actually set FRAME to 0 (at least not in the code you posted).
Further, even if you did set FRAME to 0, you are also skipping over 'timer' being zero.

This is what you were doing in your original post:
int timer = 0; //Timer starts off at zero.
timer++; //Timer is now 1, skipping zero.

//More code... several loops pass...

if(timer == 3)
{
FRAME= 3;
timer = 0; //Timer is now zero...
}

//Next loop...
timer++; //Timer is now 1, you still skipped zero.

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

#14BeerNutts  Members

Posted 10 February 2012 - 08:13 AM

You have inspired me and thanks so much you solved my problem I can't believe how strict arrays are but thanks so much I now know to be carefull when using arrays

Which is why C++ has std::vectors.

int timer = 0;
FRAME = timer;

timer++;

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

The actual reason you never saw the first frame, is because you never actually set FRAME to 0 (at least not in the code you posted).
Further, even if you did set FRAME to 0, you are also skipping over 'timer' being zero.

This is what you were doing in your original post:
int timer = 0; //Timer starts off at zero.
timer++; //Timer is now 1, skipping zero.

//More code... several loops pass...

if(timer == 3)
{
FRAME= 3;
timer = 0; //Timer is now zero...
}

//Next loop...
timer++; //Timer is now 1, you still skipped zero.

He changed it in his follow up post (see his pastebin code here:http://pastebin.com/McJdnZRR)

I saw that too, but it isn't there in his pastebin code, so i didn't comment on it.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.