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 3232146
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:07:37+00:00 2026-05-17T17:07:37+00:00

I have problem with following code. mySpriteArray=[[NSMutableArray alloc] init]; star=[CCSprite spriteWithFile:@22.png]; for(int i=0;i<10; i++)

  • 0

I have problem with following code.


mySpriteArray=[[NSMutableArray alloc] init];

star=[CCSprite spriteWithFile:@"22.png"]; for(int i=0;i<10; i++) { [mySpriteArray insertObject:star atIndex:i]; } // NSLog(@"x=%i",[mySpriteArray count]); for (int i=0; i<10; i++) // Opponents is NSMutableArray { CCSprite *tempSprite = (CCSprite *) [mySpriteArray objectAtIndex:i]; tempSprite.position=ccp(100,100); [self addChild:tempSprite]; }

}

where star is a object of CCSprite and mySpriteArray is a mutable array.The problem is that when i run the program it crash and say

* Assertion failure in -[GameScene addChild:z:tag:], /Users/salimsazzad/Desktop/balon hunter/libs/cocos2d/CCNode.m:305
2010-10-08 19:05:35.854 balon hunter[3967:207] *
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘child already added. It can’t be added again’.

i can’t understand whats wrong,i am adding 10 object,not 1 object in 10 times because CCSprite *tempSprite = (CCSprite *) [mySpriteArray objectAtIndex:i];creating a new object each time.
so what is the problem???

  • 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-05-17T17:07:38+00:00Added an answer on May 17, 2026 at 5:07 pm

    You have created your star object once and added it 10 times to array:

    star=[CCSprite spriteWithFile:@"22.png"];
    for(int i=0;i<10; i++) 
    {
        [mySpriteArray insertObject:star  atIndex:i];
    }
    

    So your array contains the same object and that’s the reason of assertion you get.

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

Sidebar

Related Questions

I have a problem compiling the following code: #include <stdio.h> #include <limits.h> int main
I have a problem with the following code: #include <stdio.h> #include <iostream> int main
Hi I have a problem with the following code: int skp = 1; do{
I have a problem with the following code: for(i = 0;(i - 1)< n;i++)
The following code demonstrates a weird problem I have in a Turbo C++ Explorer
I have a problem with the following code in an ASPX page: <script type=text/javascript>
I have a problem with the following code. I obtain the error message Exception
I have a problem getting the following code to work. open System open System.ComponentModel
I have a problem with the following code: protected void onDraw(Canvas canvas) { Paint
I have a problem in the following code: //quesry the db for image information

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.