我正在为游戏制作暂停屏幕菜单。显示暂停屏幕后,我让用户触摸屏幕以隐藏暂停屏幕并恢复游戏。这在模拟器上完美运行,但在我在实际设备上测试时不起作用。设备似乎没有响应专门针对暂停菜单的触摸。游戏的所有其他部分在模拟器和设备上都可以正常工作。它在模拟器上的工作方式很奇怪,但在设备上却不行。这是我用于暂停屏幕的代码:
- (id)init {
if ((self = [super init])) {
CGSize windowSize = [[CCDirector sharedDirector] winSize];
//windowSize.height = 768.0;
//windowSize.width = 1024.0;
CCSprite *whiteScreen = [CCSprite spriteWithFile:@"OutOfTime.png"];
whiteScreen.position = ccp(windowSize.width / 2, windowSize.height / 2);
[self addChild:whiteScreen];
CCLabelTTF *touchToDismiss = [CCLabelTTF labelWithString:@"Touch screen to continue" fontName:@"Marker Felt" fontSize:30];
touchToDismiss.color = ccBLACK;
touchToDismiss.position = ccp(windowSize.width / 2, 20);
[self addChild:touchToDismiss];
}
return self;
}
- (void)onEnter {
[super onEnter];
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
}
- (void)gameOverWithScore:(NSInteger)score {
CGSize windowSize = [[CCDirector sharedDirector] winSize];
//windowSize.height = 768.0;
//windowSize.width = 1024.0;
CCLabelTTF *touchToDismiss = [CCLabelTTF labelWithString:@"Game Over" fontName:@"Marker Felt" fontSize:75];
touchToDismiss.color = ccBLACK;
touchToDismiss.position = ccp(windowSize.width / 2, windowSize.height / 2 + 40);
[self addChild:touchToDismiss];
NSString *scoreString = [NSString stringWithFormat:@"Final Score: %d", score];
CCLabelTTF *scoreLabel = [CCLabelTTF labelWithString:scoreString fontName:@"Marker Felt" fontSize:60];
scoreLabel.color = ccBLACK;
scoreLabel.position = ccp(windowSize.width / 2, (windowSize.height / 2) - 40);
[self addChild:scoreLabel];
}
- (void)setMessage:(NSString *)message {
}
- (void)dealloc {
[super dealloc];
}
- (BOOL)ccTouchBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"haha");
return YES;
}