Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8918567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:47:18+00:00 2026-06-15T05:47:18+00:00

How can I have the same sprite in multiple locations dynamically? I have already

  • 0

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.

- (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<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]];
        }
    }
}

This gives me the error: 'NSInternalInconsistencyException', reason: 'child already added. It can't be added again'

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:47:19+00:00Added an answer on June 15, 2026 at 5:47 am

    you need to create 3 different sprite and add all 3 of them as a child.
    usually for doing stuff like this is better to use a CCBatchNode (take a look to the cocos doc).
    With a batchnode you get all the childs be drawn in 1 draw call with the only constrain that all the childs of the batchnode needs to have the texture on the same spriteSheet (or in your case if they have the same “filename”)
    for just 3 projectiles you wont have performance problems but its the correct way to design it, if you will need to have dozens of projectiles on screen without using a batchnode the game wont run smooth.

    to recap:
    create a ccbatchnode,
    add the batchnode as a child of self (i suppose its ur layer or main node)
    create 3 sprites and add them as a child of the batchnode

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is my understanding that two unequal objects can have the same hashcode. How
In theory in layered architecture you can have multiple modules on the same layer.
how can I copy the selected option between two s that have the same
Both are delegates and have the same signature, but I can not use Action
I'm trying to draw multiple shapes in the same Sprite.graphics scope, and can't seem
I have a scenario where combobox can have same string values. for exa combo
Can we have same delegate for two events ? which have same number of
In Winforms you can have two controls tied to the same datasource in a
How can one have more than a Wizard control on the same page without
In java can an instance variable and a method have the same name without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.