6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SpriteKitを試してみる12 GameOver

Last updated at Posted at 2015-07-25

iphonePlay_2015072601.gif

ゲームオーバーになった時、ゲームを止めてcontinue?をタップするまで画面を止めておきたいのでSKSceneのpausedプロパティにtrueをセットしてやれば動きを止めれる。
だがHomeボタンを押してからアプリに戻ってくるとpausedがfalseになってしまう(初期値に戻る)ので画面が動いてしまう。
対応策としてpausedをオーバーライドして別のpause管理プロパティの値をセットしてやる。

    // ゲームストップ
    var stopped : Bool = false
    
    override var paused : Bool{
        didSet {
            if(stopped && !paused) { // このif文がないと実行中にBAD_ACCESSになる
                paused = stopped
            }
        }
    }

何故Homeボタンを押したらpausedが解除されるのかは不明。バグのような動きにしか思えないが・・・。

Continue?ラベルをボタンのような動きをさせているのは以下のページ参照
タップされたらゲームオーバー時の設定を全部解除して続きからやれるようにしている。

サンプルゲーム

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?