title: How can I have the same sprite in multiple locations dynamically?
body: <p>How can I have the same sprite in multiple locations dynamically? I have already seen the other question, but, you can only do that with three sprites. I want to have a dynamic number of sprites. My objective is that I am trying to make, instead of shooting only one bullet, I  want it to shoot three or more. I have all of the math done, but, I need to draw the three sprites in a for-loop. Here is what I have so far.</p>
  
  <pre><code>- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch * touch = [touches anyObject];
      CGPoint pointOne = [touch locationInView:[touch view]];
      CGSize size = [[CCDirector sharedDirector] winSize];
      CGPoint position = turret.position;
      CGFloat degrees = angleBetweenLinesInDegrees(position, pointOne);
      turret.rotation = degrees;
      pointOne.y = size.height-pointOne.y;
      CCSprite *projectile = [CCSprite spriteWithFile:@"projectile.png"];
      projectile.position = turret.position;
  
      // Determine offset of location to projectile
      int angle = angleBetweenLinesInDegrees(position, pointOne);
      int startAngle = angle-15;
  
      int shots = 3;
  
      NSMutableArray *projectiles = [[NSMutableArray alloc] initWithCapacity:shots];
  
      // Ok to add now - we've double checked position
      for(int i = 0;i&lt;shots;i++) {
          [self addChild:projectile z:1];
  
          int angleToShoot = angle;
  
          int x = size.width;
          int y = x*tan(angle);
  
          CGPoint realDest = ccp(x,y);
  
          projectile.tag = 2;
          if (paused==0 ) {
              [_projectiles addObject:projectile];
              // Move projectile to actual endpoint
              [projectile runAction:
               [CCSequence actions:
                [CCMoveTo actionWithDuration:1 position:realDest],
                [CCCallBlockN actionWithBlock:^(CCNode *node) {
                   [_projectiles removeObject:node];
                   [node removeFromParentAndCleanup:YES];
               }],
                nil]];
          }
      }
  }
  </code></pre>
  
  <p>This gives me the error: <code>'NSInternalInconsistencyException', reason: 'child already added. It can't be added again'</code></p>