0

所以我在我的游戏中添加了一个暂停按钮,并且视图的冻结和解冻工作。但是,如果视图当前被冻结,我希望它在屏幕上显示一条消息“暂停”。但是如果我触摸我的暂停按钮,它不会显示标签。这真的很奇怪,因为我发现如果我将设备转为横向模式,就会出现“暂停”消息。(反之亦然,所以如果我在横向模式下触摸按钮并将设备转为纵向,则会出现暂停标签)

任何人都可以解决这个问题吗?

-(void)gameScene{


 //Pause
    pauseButton = [SKSpriteNode spriteNodeWithImageNamed:@"pause.jpg"];
    pauseButton.position = CGPointMake(screenWidth/2, screenHeight-80);
    pauseButton.zPosition = 5;
    pauseButton.name = @"pauseButton";
    pauseButton.size = CGSizeMake(80, 80);

    [self addChild:pauseButton];

    //Pause Label (wenn Pause gedrückt wird)
    pauseLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
    pauseLabel.text = @"PAUSE";
    pauseLabel.fontSize = 70;
    pauseLabel.position = CGPointMake(screenWidth/2, screenHeight/2);
    pauseLabel.zPosition = 5;
    pauseCount = 1;
}




-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

//Pause Button
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];

    SKNode *node = [self nodeAtPoint:location];


    if ([node.name isEqualToString:@"pauseButton"]) {            

        pauseCount++;


        if (pauseCount%2 == 0) {
            self.scene.view.paused = YES;
            [self addChild:pauseLabel];

        }

        else{
            self.scene.view.paused = NO;
            [pauseLabel runAction:remove];
        }


    }

}
4

0 回答 0