Objective c 从子层cocos2d中的菜单调用父场景中的方法
我在游戏场景中添加了一个图层(hudLayer),然后在该图层上添加了一个菜单,我想在该图层上运行函数Objective c 从子层cocos2d中的菜单调用父场景中的方法,objective-c,ios,cocos2d-iphone,Objective C,Ios,Cocos2d Iphone,我在游戏场景中添加了一个图层(hudLayer),然后在该图层上添加了一个菜单,我想在该图层上运行函数-(void)pauseGame{ 方法} 我正试图这样实施: - (void) addPauseButton: (CCScene *) parent { pauseButton = [CCMenuItemImage itemWithNormalImage:@"pause.png" selectedImage:nil target:parent selector:@selector(pauseG
-(void)pauseGame{
方法}
我正试图这样实施:
- (void) addPauseButton: (CCScene *) parent {
pauseButton = [CCMenuItemImage itemWithNormalImage:@"pause.png" selectedImage:nil target:parent selector:@selector(pauseGame:)];
pause = [CCMenu menuWithItems:pauseButton, nil];
[hudLayer addChild: pause];
if (device == @"iPad") {
pause.position = ccp(40,40);
}
else if (device == @"iPhoneFive") {
pause.position = ccp(290,30);
}
else {
pause.position = ccp(290,30);
}
}
- (id)init {
if( (self=[super init])) {
paused = FALSE;
CGSize screenSize = [CCDirector sharedDirector].winSize;
hudLayer = [[[CCLayer alloc] init] autorelease];
[self addChild:hudLayer z:2]; // adds hudLayer
gameLayer = [[[CCLayer alloc] init] autorelease];
[self addChild:gameLayer z:1];
pauseMenu = [[[CCLayer alloc] init] autorelease];
[self addChild:pauseMenu z:4];
[self setupWorld];
[self addPauseButton:self]; //calls method to add pause button to hudLayer sending it the scene as a variable
CGPoint offScreenPoint = ccp(screenSize.width+(screenSize.width/2), 0);
pauseMenu.position = offScreenPoint;
self.motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
if (motionManager.isDeviceMotionAvailable) {
[motionManager startDeviceMotionUpdates];
}
self.iPadBool = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
if (iPadBool) {
device = @"iPad";
}
else if (screenSize.height > 490) {
device = @"iPhoneFive";
}
else {
device = @"iPhone";
}
NSLog(@"the current device is a, %@", device);
[self schedule:@selector(update:)];
}
return self;
}
但是这会引发错误:*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[Game Play pauseGame:]:未识别的选择器发送到实例0x11d310e0'完全不知道原因:/any idea's?选择器应
@selector(pauseGame)
没有结肠。它不需要参数。方法应为:
-(void) pauseGame
{
}
是的,冒号表示参数,所以对于您的示例,它找不到只有一个参数的选择器。