- (BOOL)ccTouchBegan在模拟器上响应,但不在设备上
问题描述:
我正在制作游戏的暂停屏幕菜单。显示暂停屏幕后,我让用户触摸屏幕以隐藏暂停屏幕并恢复游戏。这在模拟器上完美工作,但在实际设备上测试时不起作用。看起来设备不响应专门用于暂停菜单的触摸。游戏的其他部分都可以在模拟器和设备上正常工作。它很奇怪它如何在模拟器上工作,但不在设备上。这是我对暂停画面代码:- (BOOL)ccTouchBegan在模拟器上响应,但不在设备上
- (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;
}
答
你或许应该增加您的init
self.isTouchEnabled = YES;
以下行你必须为每一个CCLayer做到这一点,你有一个具有触摸事件。
编辑:只注意到你的ccTouchBegan只打印日志。 该日志很容易在XCode的调试窗口中查看,但是在设备中它对用户是隐藏的。 尝试做别的事情。
谢谢Kurama!其实想到我做错了什么。我正在使用 [[CCDirector sharedDirector]暂停]; 暂停我的游戏。有趣的是,模拟器仍然响应触摸,但该设备没有! – bakwarte 2012-07-31 22:21:57
很高兴知道:) – KuramaYoko 2012-08-01 02:55:10