title: Animation in cocos2d crashes
body: <p>I am having trouble with my game, it was running fine until i tried to add the animation, now whenever i go to shoot it crashes my game and i cant work out what is wrong with my animation code. Below i will put in all the code that causes the ninja star to shoot but as i said i believe the error is in the animation.</p>
  
  <p>ccsprite Projectile is what gets shoot and what im trying to animate </p>
  
  <pre><code>- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  if (StrategyBullet &gt; 0) {
      //SOME IF STATEMENTS
      if (Strategyscore == 47) {
          StrategyBullet = StrategyBullet +5;
      }
      if (Strategyscore == 97) {
          StrategyBullet = StrategyBullet +5;
      }
      if (Strategyscore == 197) {
          StrategyBullet = StrategyBullet +10;
      }
      // Choose one of the touches to work with
      UITouch *touch = [touches anyObject];
      CGPoint location = [self convertTouchToNodeSpace:touch];
  
      // Set up initial location of projectile
      CGSize winSize = [[CCDirector sharedDirector] winSize];
      CCSprite *projectile = [CCSprite spriteWithFile:@"ninja star 1.png"];
      [self addChild:projectile z:2];
  
      {
          NSString *animationName = @"UNIQUE_ANIMATION_NAME";
  
          CCAnimation* animation = nil;
          animation = [[CCAnimationCache sharedAnimationCache]  animationByName:animationName];
  
          if(!animation)
          {
              NSMutableArray *animFrames = [NSMutableArray array];
  
              for( int i=1;i&lt;=5;i++)
              {
                  NSString* path = [NSString stringWithFormat:@"ninja star %d.png", i];
                  CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:path];
                  CGSize texSize = tex.contentSize;
                  CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
                  CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:tex rect:texRect];
                  [animFrames addObject:frame];
              }
  
              animation = [CCAnimation animationWithSpriteFrames:animFrames];
  
              animation.delayPerUnit = 0.175f;
              animation.restoreOriginalFrame = YES;
  
              [[CCAnimationCache sharedAnimationCache] addAnimation:animation name:animationName];
          }
  
          if(animation)
          {
              CCAnimate *animAction  = [CCAnimate actionWithAnimation:animation];
              [projectile runAction:animAction];
          }
      }
  
      projectile.position = ccp(20, winSize.height/2);
  
      // Determine offset of location to projectile
      CGPoint offset = ccpSub(location, projectile.position);
  
      // Bail out if you are shooting down or backwards
      if (offset.x &lt;= 0) return;
  
      // Ok to add now - we've double checked position
      [self addChild:projectile];
  
      int realX = winSize.width + (projectile.contentSize.width/2);
      float ratio = (float) offset.y / (float) offset.x;
      int realY = (realX * ratio) + projectile.position.y;
      CGPoint realDest = ccp(realX, realY);
  
      // Determine the length of how far you're shooting
      int offRealX = realX - projectile.position.x;
      int offRealY = realY - projectile.position.y;
      float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
      float velocity = 480/1; // 480pixels/1sec
      float realMoveDuration = length/velocity;
      // collison stuff
      projectile.tag = 2;
      [_projectiles addObject:projectile];
      StrategyBullet --;
      [StrategyBulletLabel setString:[NSString stringWithFormat:@"%d", StrategyBullet]];
      // Move projectile to actual endpoint
      [projectile runAction:
       [CCSequence actions:
        [CCMoveTo actionWithDuration:realMoveDuration position:realDest],
        [CCCallBlockN actionWithBlock:^(CCNode *node) {
           [node removeFromParentAndCleanup:YES];
           // CCCallBlockN in ccTouchesEnded
           [_projectiles removeObject:node];
  
       }],
        nil]];
  
  }
  </code></pre>
  
  <p>}</p>