0

我正在为游戏制作暂停屏幕菜单。显示暂停屏幕后,我让用户触摸屏幕以隐藏暂停屏幕并恢复游戏。这在模拟器上完美运行,但在我在实际设备上测试时不起作用。设备似乎没有响应专门针对暂停菜单的触摸。游戏的所有其他部分在模拟器和设备上都可以正常工作。它在模拟器上的工作方式很奇怪,但在设备上却不行。这是我用于暂停屏幕的代码:

- (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;
}
4

1 回答 1

0

您可能应该在您的 init 中添加以下行

self.isTouchEnabled = YES;

您必须为您拥有的每个具有触摸事件的 CCLayer 执行此操作。

编辑:刚刚注意到你的 ccTouchBegan 只打印一个日志。这个日志很容易在 XCode 的调试窗口中查看,但在设备中它对用户是隐藏的。尝试做其他事情。

于 2012-07-31T20:11:08.583 回答