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

  • Home
  • SEARCH
  • 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 8110145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:38:56+00:00 2026-06-06T01:38:56+00:00

I am quite new to Objective-C and Cocos2d, and i don’t really understand why

  • 0

I am quite new to Objective-C and Cocos2d, and i don’t really understand why i am getting the following error with the following code. Could you please help ?

- (NSArray *) menuItemsArray
{   
    NSMutableArray *array = [NSMutableArray alloc];
    for (Player * player in playersArray) {
        NSLog(@"creating menu item with image %@",player.imageFilename);
        CCLayer *newPage = [[CCLayer alloc] init];
        CCMenuItemImage *titem = [CCMenuItemImage itemFromNormalImage:player.imageFilename
                                                    selectedImage:player.imageFilename
                                                           target:self selector:@selector(playerSelected:)];

        CCMenu *menu = [CCMenu menuWithItems: titem, nil];
        menu.position = ccp(self.contentSize.width/2, self.contentSize.height/2);

        NSLog(@"before adding item to layer");
        //[titem removeFromParentWithCleanup:YES];
        [newPage addChild:titem];
        //[newPage release];
        NSLog(@"after adding item to layer");
        [array addObject:newPage];

        /*
        [titem release];*/
        //[newPage release];
        //[menu release];
    }    
return array;
}

and i get the error:

2012-06-15 17:13:11.003 Killer[3222:707] *** Assertion failure in -[CCLayer     addChild:z:tag:], /Users/max/Documents/workspace/Killer/Killer/libs/cocos2d/CCNode.m:388
2012-06-15 17:13:11.006 Killer[3222:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'child already added. It can't be added again'

Sorry if this question is very low level… and thanks if you can help me ! 🙂

  • 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-06T01:38:58+00:00Added an answer on June 6, 2026 at 1:38 am

    Your error is that you are trying to add created menuItem to two parents. add it to the menu only. Then add menu to the layer. Replace your line

    [newPage addChild:titem];
    

    with this one

    [newPage addChild:menu];
    

    and you will receive an array of pages for every player.

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

Sidebar

Related Questions

I'm quite new in Objective-c leaning so if my question is too stupid, please
OK, I am quite new to this Objective-C and JSON thing, so please bare
I am new to Objective-C and could use some help with a problem that
first of all please let me say that I am quite new to objective
I am quite new with jQuery, the following code is a collage of 2
I'm quite new to Objective C development and I was wondering how I could
I am quite new to Objective C for the iPhone, so I hope you
I'm quite new to objective-j and the framework so I was attempting to drill
I'm quite new to xcode na objective-c so I'm sorry for the dumb question.
I am quite new to Core Data, and actually Objective-C as a whole, so

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.