Dear stackoverflow community,
I have a simple menu that have to be dynamics. With dynamics I mean that I have a different number of element each time that I open that menu.
so, I have this NSMutableArray:
NSMutableArray *answerList = [[NSArray alloc]init];
for(int i=0; i<countAnswers; i++){
CCLabelTTF *labelAnswer = [CCLabelTTF labelWithString:answer fontName:@"Marker Felt" fontSize:40];
CCMenuItemLabel * MenuItemAnswer = [CCMenuItemLabel itemWithLabel:labelAnswer target:self selector:@selector(vedidimorire)];
[answerList addObject:MenuItemAnswer];
}
the code is simplified, but what is important is that I have an array with various CCMenuItem.
Now I wont create the menuItems with this elements
CCMenu * myMenu = [CCMenu menuWithItems: ????? ];
How can I do it?
Thanks a lot in advance for the answer!
Benza
In your
answerListmutable array, there areCCMenuItemLabelobjects.Now if you want to create menus, first you have to count how many answers are there in
answerListand then create correspondingCCMenuwith each these items in[CCMenu menuWithItems:.First determine the minimum and maximum answers that can be in
answerListarray.Let minAnswer = 3 and maxAnswer = 6
Then,
int currentAnswerCount = [answerList count]; CCmenu myMenu; if (currentAnswerCount == minAnswer) { myMenu = [CCMenu menuWithItems:[answerList objectAtIndex:0], [answerList objectAtIndex:1], [answerList objectAtIndex:2]]; } else if (currentAnswerCount == minAnwer + 1 { myMenu = [CCMenu menuWithItems:[answerList objectAtIndex:0], [answerList objectAtIndex:1], [answerList objectAtIndex:2], [answerList objectAtIndex:3]]; } .. .. upto maxAnswer. [self addChild:myMenu];Hope this helps!