SpriteKit Pause and Resume SKView

前端 未结 1 551
不知归路
不知归路 2021-01-14 21:52

I want to Pause and Unpause a Scene in SpriteKit, with 2 Buttons on the same position. While the Scene is running, I want to show the \'Pause\' Button. While the Scene is p

1条回答
  •  被撕碎了的回忆
    2021-01-14 22:01

    You can't update the button (or anything else in the scene) while the SKView is paused. In your touchesBegan method, you are pausing the view before updating the button (changing the order won't work). You will need to return to the run loop so your button is updated before pausing the game. Here's one way to do that:

    This calls a method to pause the view after a short delay. Add this after your [self Resume] statement in touchesBegan, and delete self.scene.view.paused = YES.

        [self performSelector:@selector(pauseGame) withObject:nil afterDelay:1/60.0];
    

    This method pauses the SKView. Add this to your MyScene.m

    - (void) pauseGame
    {
        self.scene.view.paused = YES;
    }
    

    0 讨论(0)
提交回复
热议问题