SKAction resumes when appDidBecomeActive () even when the game pauses until appDidResignActive ()

I have an iOS SpriteKit game that has a moving node. When you press the pause button, a line is called node.isPaused = true. But if you press pause, then minimize the application and restart it, node will return to moving, even in the transparent Pause menu.

I tried the sentence from the following answer: Answer1 . But even if I call the scene method pauseGamein any state, the function is called, but node is restarted even in the pause menu.

I also tried to answer: Answer2 . But CBApplicationDidBecomeActive()not even called out.

And I even tried using scene?.view?.isPaused = truelink 1 in the methods, but it does not work.

Please, help.

I know that there are many similar questions, but none of them seem to help to decide what I have. (and even, the question from the second link did not even receive the accepted answer)

+4
source share
1 answer

Change the pauseGame () and resumeGame () methods to:

private func pauseGame() {

        node.speed = 0.0
        gameState = .paused
        pauseLayer.run(SKAction.fadeAlpha(to: 0.5, duration: 1))


 }
 private func resumeGame() {
        pauseLayer.run(.fadeOut(withDuration: 1))
        node.speed = 1.0
        gameState = .inProgress
 }

Note that I use the speed property instead of the isPaused property ... That's all you need to do. I can’t say why this happens because this behavior is not documented, but I have already seen it and wrote about it, perhaps in more detail in some of my previous posts.

+2
source

Source: https://habr.com/ru/post/1681863/


All Articles