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:]: 認識されないセレクターがインスタンス 0x11d310e0 に送信されました'