Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working on a XNA WP7 card game whose basic prototype is complete. In game screen, 6 cards are displayed at a time (3 for each of the two players say 1,2 and 3).

If player A attacks one of player B's card then I want to show an animation over player B's card i.e the victim card(say a claw scratch for e.g.)

My question is how do I approach with the animation system so that I can draw an animation over a card upon certain events e.g. dead, fire, claw attack etc.

I have an attack function which detects which type of card is attacking which type of card. Depending on the type of attacker card I want to display the animation on the victim card.

Can I call animation classes function for different animations in the attack function itself without actually having to call separate draw and update functions. If so, how?

Also how do I play sound at the same time when the animation is going on?

EDIT- Heres what I have done.

I took your advice and created an animation routine in a different class. Here's how it works.

  1. I have a separate Animation.cs class file (where animation occurs)

  2. I have a wrapper class called CardAnimation which has a Dictionary object as animations with animation type as key and animation object as value.

  3. I created a static object of CardAnimation class in Card class so that its not created every time I call animation routine.

  4. I am calling the card's update method from another class called MAINGAMESCREEN.

Here's the flow of Update methods

MAINGAMESCREEN -> CARD -> CARDANIMATION -> ANIMATION

Animation works but it occurs very fast that I can see only first frame. Same animation code works fine in an independent project. What can I do to slow it down?

share|improve this question
add comment

2 Answers

You can just draw the animation over the card by a second draw call. The code will look something like this:

SpriteBatch.Begin();
SpriteBatch.Draw(Cards);
if(Animation_should_play);
 SpriteBatch.Draw(Animation);
SpriteBatch.End();

You can also define a Routine in every card (if you are using OOP) for the Animation and pass the SpriteBatch as an Parameter: In the card class

public void DrawDeathAnim(SpriteBatch batch)
 Batch.Draw(Animation)

Note that you don´t need to call Begin and End if you are calling this function from inside the main Draw logic.

EDIT:

To control the speed of your animation you need to pass he elapsed time since the last update and multiply your values with it. This is passed to XNAs update routine as gameTime.

share|improve this answer
    
Please check the edit section of my original post. I was unable to post everything in the comment. Thanks. –  Chandan Pednekar Oct 23 '12 at 11:26
add comment

You need to control(slow) the animation update somehow, i would create an update event which is raised each time you want the next frame.

here is a good example http://www.xnawiki.com/index.php/Event_Driven_Timer

Good luck :)

share|improve this answer
    
I created an independent animation class rather than integrating it with the Card object. Thank you for your time :) –  Chandan Pednekar Oct 25 '12 at 15:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.