I have a child layer that I’m adding to the scene which contains a menu, it is initialized like so:
- (id) init
{
if((self=[super init]))
{
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCMenuItemImage* attackButton = [CCMenuItemImage
itemFromNormalImage:@"btnAttack.png"
selectedImage:@"btnAttack.png"
target: self
selector:@selector(attack)];
CCMenu* menu = [CCMenu menuWithItems:attackButton, nil];
menu.position = ccp(winSize.width-80,winSize.height-140);
[menu alignItemsHorizontally];
[self addChild:menu];
}
return self;
}
This crashes with a SIGABRT error unless I change the target: to ‘nil’. Why is this not working and how can I fix it?
This should crash if you don’t have attack: defined in your class.
Do you really need a parameter to attack?
Easy steps to check if that’s your problem:
1) remove the param, change the code to:
2) add the attack method, and check the console output:
To better understand where is the problem, show the breakpoints in your navigator bar, click the plus button and add exception breakpoint … so when the app crashes (if still does) you can see the call stack and see what’s wrong