我正在向我的 gamePlay 场景添加一个图层(hudLayer),然后向我要从中运行功能的那个图层添加一个菜单- (void) pauseGame {
method in here }
我正在尝试这样实现:
- (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”而终止应用程序,原因:“-[gamePlay pauseGame:]: unrecognized selector sent to instance 0x11d310e0”根本不知道为什么:/任何想法?