我正在为游戏制作暂停屏幕菜单。在显示暂停屏幕后,我让用户触摸屏幕以隐藏暂停屏幕并恢复游戏。这在模拟器上工作得很好但在我在实际设备上测试时不起作用。设备似乎没有响应专门用于暂停菜单的触摸。游戏的每个其他部分在模拟器和设备上都能正常工作。它是如何在模拟器上工作而不是在设备上工作的。这是我暂停屏幕的代码:
- (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;
}
答案 0 :(得分:0)
您可能应该在init
上添加以下行self.isTouchEnabled = YES;
您必须为每个有触摸事件的CCLayer执行此操作。
编辑:注意到你的ccTouchBegan只打印一个日志。 可以在XCode的调试窗口中轻松查看此日志,但在设备中,它对用户是隐藏的。 尝试做别的事。