//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;
}
}
It starts with class1 after i pressed a button it adds child of class2 with another menu.
How do i remove child class2 then add different sprite according to the buttons i pressed in class2? Thanks for help. Is it possible to use the tags in class2 inside class1?
Just go through following code.