title: How do I make an animation 2 wait for animation 1 to complete before executing, in Cocos2D, Objective-C
body: <p>In my program, when you tap the screen in the iOS Sim, cards are dealt out, using CCMoveTo.  The animation takes .4 seconds to complete.  Tap the screen again and the next set of cards is dealt.  This second animation takes .4 seconds also.  All I want to do is prohibit my program from dealing out that second set of cards before the first animation is complete.  Tried sleep() and, obviously, couldn't achieve the desired effect.  Also tried Cocos2D's CCDelayTime a few different ways and couldn't produce the desired result.  What's the easiest and/or most memory-efficient way to go about doing this?</p>
  
  <p>EDIT:  @crackity_jones - Here's my HelloWorldLayer file and the category I created for CCSprite to allow movement:</p>
  
  <p>HelloWorldLayer.h</p>
  
  <pre><code>#import &lt;GameKit/GameKit.h&gt;
  #import "CCSprite+MoveActions.h"
  #import "cocos2d.h"
  
      // globals
  CCSprite *card1;
  ...
  CCSprite *card9;
  
  @interface HelloWorldLayer : CCLayer {
      NSMutableArray *deck;
      ...
      int touchCount;
  }
  
  ...
  
  @end
  </code></pre>
  
  <p>HelloWorldLayer.m</p>
  
  <pre><code>...
  
  -(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
      touchCount++;
      [self nextRound];
  }
  
  // one method to handle all rounds dealt
  -(void)nextRound {
      if (touchCount == 1) {
          [self removeAllCards];
          [deck shuffle];
          [self dealFirstRound];
      } else if (touchCount == 2) {
          [self dealSecondRound];
      } else if (touchCount == 3) {
          [self dealThirdRound];
      } else if (touchCount == 4) {
          [self dealFourthRound];
      touchCount = 0;
      }
  }
  
  -(NSMutableArray *)makeDeck {
      // create mutable array of 52 card sprites
  }
  
  -(void)dealFirstRound {
      ...
      // declare, define, add card objects to layer at start-point here
      …
      // the "moveToPositionX" methods contain the animation code
      [firstCard moveToPosition1];
      [secondCard …2];
      [third...3];
      [fourth...4];
      }
  
  // Also methods for removing all rounds of cards
  …
  @end
  </code></pre>
  
  <p>CCSprite (MoveActions)  </p>
  
  <pre><code>#import "CCSprite+MoveActions.h"
  #define kCardTravelTime .1
  
  @implementation CCSprite (MoveActions)
  
  -(void)moveToPosition1 {
      CGSize size = [[CCDirector sharedDirector] winSize];
      [self runAction:[CCMoveTo actionWithDuration:kCardTravelTime
                                          position:CGPointMake(size.width/2 - card1.contentSize.width/4, card1.contentSize.height/2 + holeCard1.contentSize.height/5)]];
      CCDelayTime *waitTime = [CCDelayTime actionWithDuration:.4];
      [self runAction:waitTime];
  }
  
  -(void)moveToPosition2 {
      CGSize size = [[CCDirector sharedDirector] winSize];
      CCDelayTime *delay = [CCDelayTime actionWithDuration:.2];
      CCMoveTo *move = [CCMoveTo actionWithDuration:kCardTravelTime
                                          position:CGPointMake(size.width/2 + card1.contentSize.width/4, card1.contentSize.height/2 + holeCard1.contentSize.height/5)];
      [self runAction:[CCSequence actions:delay, move, nil]];
  }
  // rest of the methods 3-9 look like the above, essentially
  
  @end
  </code></pre>