• 15
• 15
• 11
• 9
• 10

# Sync animation with effects?

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

## Recommended Posts

I have a question on how to sycn amimation with the related effect. An example: if a character shoots an arrow at another character and kills him, the character should not fall down until after the arrow has impacted. In a turn-based combat situation you can calculate immediately what the result of an action will be (a kill result from the arrow attack), but must wait to apply the effect until after the animaton plays. What's the best way to handle this situation? Currently, I've been cloning the target character, applying the effect to the clone, then replacing the target character with his clone after the animation plays. It works, but seems excessive. Most of the examples I've found use collision detection which is more that I really need. Any help is appreciated. Regards

##### Share on other sites
Your arrow animation is probably a function by itself. Why not just encapsulate that function inside a larger wrapper that calls the animation function, calculates the result, and plays the proper response animation? You can set your arrow animation to play until it reaches your destination tile so no reactions will be made until it's finished.

void animate_attack(Actor *attacker,Actor *target) {   attacker->attack_animation(attacker->loc,target->loc);   calculate_damage(attacker->damage,target->defense);   if target->hp <= 0 {      target->death_animation();   } else target->hit_animation();}

...in pseudo code.

##### Share on other sites
Thanks for the feedback. Unless I'm reading it incorrectly your example works if you are not running a "game loop". I can't draw the arrow moving from the start location to end location on its own since other things might be animated at the same time (torches, water, etc...) during each frame.

As an fyi, I'm using the XNA framework.

Regards

##### Share on other sites
You're absolutely right, and from how I read your example, it sounded like no parallel animations would be used (sorta like Civilization without the environment animations). I'm on my way to work, but I'll think on this a bit more. Cheers.

##### Share on other sites
Do you have this all encapsulated in an arrow class?

If so then set the target pointer when you fire the arrow
Have a function called in the arrow when the animation finishes
In this function have the:

{   calculate_damage(attacker->damage, target->defense);   if target->hp <= 0 {      target->death_animation();   } else target->hit_animation();}

It should work if you have all this wrapped in a class.