🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

making and animation play only once

Started by
8 comments, last by Mr. Z 24 years, 5 months ago
I want my characters death animation to only play once - but it loops over and over again. How do I prevent this later,
Advertisement
Do something like this.

#define SPRITE_DEAD 0
#define SPRITE_ALIVE 1

if(sprite->state == SPRITE_ALIVE)
{
// play death animation

// set the sprite state to dead
sprite->state = SPRITE_DEAD;
}

So after the death animation has played the sprite state will be dead and wont play again. Hope it helps. Later.
"I have realised that maths can explain everything. How it can is unimportant, I want to know why." -Me
Thank you for the reply but this doesn''t seem to work for me. If I set it up like this the death animation doesn''t play.
I''m looking for a way to play an animation for like 30 game loops. And from what I understand, your suggestion does not give me that. Maybe I just don''t understand. If this is the case please correct me because I really want to fix this.

Thank You again.

In that case you need to apply some kind of counter to the example above. You check for both PLAY_DEAD_ANIMATION and ANIMATION_MAXFRAME as an example.
I''m sorry but I''m not sure I understand that last post. It sounded like what I''m looking for though. Any chance of getting an example?
All you need to do is, when you are animating your sprite, check like this
#define SPRITE_MAXFRAME 10   // the last frame in the animationvoid AnimateSprite(){if(sprite->state == DEAD){ if(sprite->frame == SPRITE_MAXFRAME)   sprite->state = SPRITE_STATE_NULL; // or something else else   sprite->NextFrame();}} 


Do you get what I mean?

------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
I kind of sort of understand you but won''t using this way cause my animation to play for different lengths of time on different computers?
One frame of character animation per screen frame redraw. Unless you add in some code to only update the screen 30 times a second.
William Reiach - Human Extrodinaire

Marlene and Me


If you want to time it so that you go through your animation in 30 seconds, for example, and you have ten frames, add a time variable for when the sprite died, and every frame, if a multiple of three seconds has passed since the sprite died, increment the frame count. Then after 10 increments, stop playing the animation (deallocate the sprite or whatever) like in the previous code snippet.
Yeah I was assuming you had some timing code within your code for animating the sprites, and the death animation would run according to that.

This topic is closed to new replies.

Advertisement