Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

ios - How to keep SpriteKit scene paused when app becomes active?

Is there anyway to prevent SpriteKit from automatically unpausing a scene when entering foreground/becoming active?

I set paused = true and want it to remain so even when the app becomes active again after having been sent to the background.

I should add that I'm doing this in swift, though I would not have expected the behaviour to be different in this regard.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure if it is the same in objective C, but in swift I had to "override" a callback function that SKView calls behind the scenes,

func CBApplicationDidBecomeActive()
{

}

This function was causing paused to be reset.

(note override keyword should not be applied)

In some cases where you want to just retain the state of pause, make a new variable instead and override the isPaused method.

class GameScene:SKScene
{
  var realPaused = false
  {
     didSet
     {
         isPaused = realPaused
     }
  }
  override var isPaused : Bool
  {
    get
    {
       return realPaused
    }
    set
    {
      //we do not want to use newValue because it is being set without our knowledge
      paused = realPaused
    }
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...