如何处理CCMenuItemToggle类?

时间:2011-10-11 10:14:59

标签: iphone cocos2d-iphone

我尝试使用cocos2d为ios编写游戏。我想使用CCMenu.But创建一个菜单,当我使用CCMenuItemToggle类时,它会显示一条警告,例如“ removeChildByTag:child not found!< /strong>“。实际上我没有做任何删除操作。当我一步一步地调试它时,问题集中在用CCMenuItemToggle创建的菜单项上。所以如何解决问题。谢谢你的建议。

- (id) init{
[super init];

[CCMenuItemFont setFontName:@"American Typewriter"];
[CCMenuItemFont setFontSize:18];

CCMenuItemFont *title1 = [CCMenuItemFont itemFromString:@"Sound"];
[title1 setIsEnabled:NO];

[CCMenuItemFont setFontName:@"Marker Felt"];
[CCMenuItemFont setFontSize:26];
    //FIXME:
CCMenuItemToggle *item1 = [CCMenuItemToggle itemWithTarget:self selector:nil items:[CCMenuItemFont itemFromString:@"On"],[CCMenuItemFont itemFromString:@"Off"], nil];

[CCMenuItemFont setFontName:@"American Typewriter"];
[CCMenuItemFont setFontSize:18];

CCMenuItemFont *title2 = [CCMenuItemFont itemFromString:@"Music"];
[title2 setIsEnabled:NO];

[CCMenuItemFont setFontName:@"Marker Felt"];
[CCMenuItemFont setFontSize:26];
//FIXME:
CCMenuItemToggle *item2 = [CCMenuItemToggle itemWithTarget:self selector:nil items:[CCMenuItemFont itemFromString:@"On"],[CCMenuItemFont itemFromString:@"Off"], nil];

[CCMenuItemFont setFontName:@"Marker Felt"];
[CCMenuItemFont setFontSize:26];

CCLabelBMFont *label = [CCLabelBMFont labelWithString:@"Go back" fntFile:@"font01.fnt"];
CCMenuItemLabel *back = [CCMenuItemLabel itemWithLabel:label target:self selector:@selector(backCallback:)];
back.scale = 0.8;

CCMenu *menu = [CCMenu menuWithItems:title1,title2,item1,item2,back, nil];
[menu alignItemsInColumns:[NSNumber numberWithUnsignedInt:2],[NSNumber numberWithUnsignedInt:2],[NSNumber numberWithUnsignedInt:1], nil];
back.position = ccp(back.position.x, back.position.y-20);
[self addChild:menu];
return self;
}

1 个答案:

答案 0 :(得分:1)