0

Here is my problem. I got a classic CCLayer subclass. In the init method, I create a CCMenuItem, and add it to my main layer :

CCMenuItemFont *back = [CCMenuItemFont itemFromString:@"back" target:self selector:@selector(back)];
    [back setPosition:CGPointMake(30, 30)];
    [self addChild:back];

I don't understand why, the method 'back' is not called.

Thanks in advance

Bob
  • 1

2 Answers2

1

You need to add your menu items to a CCMenu, not directly to your layer.

CCMenuItemFont *back = [CCMenuItemFont itemFromString:@"back" target:self selector:@selector(back)];
[back setPosition:CGPointMake(30, 30)];

CCMenu *menu = [CCMenu menuWithItems:back,nil];
[menu setPosition:CGPointZero];
[self addChild:menu];

If that doesn't work, your back method may need to accept the parameter passed when the menu button is pressed, like this:

-(void) back:(CCMenuItem*) item;

If that's the case you'll need to add the parameter to the @selector call:

...selector:@selector(back:)];
Ian Hatch
  • 1,241
  • 2
  • 8
  • 4
0

try this.

CCMenuItemFont *back = [CCMenuItemFont itemFromString:@"back" target:self selector:@selector(back:)];

and change your back method to be..

-(void) back: (id) sender {
Bongeh
  • 2,300
  • 2
  • 18
  • 30