我设置CCMenu,菜单项如下:
CCLabelTTF *label1 = [CCLabelTTF labelWithString:@"level 1" fontName:@"Marker Felt" fontSize:32];
CCLabelTTF *label2 = [CCLabelTTF labelWithString:@"level 2" fontName:@"Marker Felt" fontSize:32];
CCLabelTTF *label3 = [CCLabelTTF labelWithString:@"level 3" fontName:@"Marker Felt" fontSize:32];
CCLabelTTF *label4 = [CCLabelTTF labelWithString:@"level 4" fontName:@"Marker Felt" fontSize:32];
CCMenuItem *level1 = [CCMenuItemLabel itemWithLabel:label1 target:self selector:@selector(levelSelect:)];
level1.tag = 1;
CCMenuItem *level2 = [CCMenuItemLabel itemWithLabel:label2 target:self selector:@selector(levelSelect:)];
level2.tag = 2;
CCMenuItem *level3 = [CCMenuItemLabel itemWithLabel:label3 target:self selector:@selector(levelSelect:)];
level3.tag = 3;
CCMenuItem *level4 = [CCMenuItemLabel itemWithLabel:label4 target:self selector:@selector(levelSelect:)];
level4.tag = 4;
CCMenu *menu = [CCMenu menuWithItems:level1, level2, level3, level4, nil];
[menu alignItemsVerticallyWithPadding:20];
有没有办法让se循环遍历每个CCMenuItem?我想基本上想要将其设置为no,如果它的标签小于其他东西。例如:
for (ALL MENU ITEMS) {
if (THAT MENU ITEM.tag < 4) {
THAT MENU ITEM.enabled = NO;
}
}
提前致谢
答案 0 :(得分:4)
CCMenuItems
被添加为CCMenu的子级,因此为了遍历它们,您可以这样做.-
for (CCMenuItem *item in [menu children]) {
if (item.tag < 4) {
item.enabled = NO;
}
}