0
//class1
- (void)starButtonTapped:(CCMenuItem*)sender {
switch(sender.tag) {
case 1: NSLog(@"Pressed 1");
class2 *myFood = [[class2 alloc]init];
[self addChild:myFood];
break;
}
}
//class2
-(id) init
{
if((self=[super init])) {
//ccmenu
CCMenuItem *food1 = [CCMenuItemImage itemFromNormalImage:@"Food0001.png" selectedImage:@"Food0002.png" target:self selector:@selector(food:)];
CCMenuItem *food2 = [CCMenuItemImage itemFromNormalImage:@"Food0003.png" selectedImage:@"Food0004.png" target:self selector:@selector(food:)];
food1.tag = 1;
food2.tag =2
CCMenu *menu1 = [CCMenu menuWithItems:food1,food2, nil];
[self addChild:menu1];
}
return self;
}
-(void)food:(CCMenuItem*)sender{
switch (sender.tag) {
case 1:
NSLog(@"food1");
//go back to class2 and add food1 sprite
break;
case 2:
NSLog(@"food1");
//go back to class2 and add food2 sprite
break;
default:
break;
}
}
在按下按鈕後,它將從class1開始,它將class2的子項添加到另一個菜單。 我如何刪除孩子class2,然後根據我在class2中按下的按鈕添加不同的精靈?感謝幫助。是否有可能在class1中的class2中使用標籤?如何在不同的類中訪問CCMenu的標籤