APP DELEGATEクラッシュする問題は、App SpriteKitベースに
を返した後、私はプログラミングで非常に初心者だと、私のアプリを開発しながら、unsolutionable問題が現れたプレーを押します。ユーザーがアプリを離れるときにゲームを一時停止しようとしましたが、帰りが望めば、ホームボタンが押されてからゲームが一時停止します。私の難しさは、ユーザーがゲームを一時停止して戻ってきてもアプリケーションが完璧に動作することですが、ユーザーがゲームを一時停止して終了すると、「スレッド1:シグナルSIGARBT」というエラーメッセージが表示されます。ゲームクラッシュあなたが私のゲームの上にのぞき見を取る場合、私は非常に満足していると思います
コード自体
AppDelegate.swift
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
//pause when leaving app
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("pauseState"), name: "pauseState", object: nil)
}
GameScene.swift
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
var gameLayer = SKNode()
var pauseLayer = SKNode()
var gameStarted = Bool()
var pauseButton = SKSpriteNode()
var playButton = SKSpriteNode()
func setupPauseButton(){
//Pause
pauseButton = SKSpriteNode (imageNamed: "pause")
pauseButton.setScale(0.25)
pauseButton.position = CGPoint(x: self.frame.width/10, y: self.frame.height/1.5)
//pauseButton.zPosition = 3
}
func setupPlayButton(){
//Play
playButton = SKSpriteNode (imageNamed: "play")
playButton.setScale(0.15)
playButton.position = CGPoint(x: self.frame.width/10, y: self.frame.height/1.5)
//playButton.zPosition = 3
}
//layers
func createGameLayer(){
self.physicsWorld.contactDelegate = self
setupPauseButton()
gameLayer.addChild(pauseButton) //add pauseButton to gameLayer
pauseButton.hidden = true
}
func createPauseLayer(){
//Play
setupPlayButton()
pauseLayer.addChild(playButton) //add playButton to pauseLayer
}
override func didMoveToView(view: SKView) {
/* Setup your scene here */
//pause when coming back
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("pauseState"), name: "pauseState", object: nil)
self.addChild(gameLayer)
createGameLayer()
createPauseLayer()
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
//run only if game is running
if gameLayer.paused == false{
//pauseButton shows when starting to play
pauseButton.hidden = false
}
//when touch buttons/screen
for touch in touches{
let location = touch.locationInNode(self)
let node = nodeAtPoint(location)
if node == pauseButton{
pauseState()
}
else if node == playButton{
playState()
}
else{
if gameStarted == false{ //game didn't start yet
gameStarted = true
Character.physicsBody?.affectedByGravity = true //start falling when touch the screen
//first jump
Character.physicsBody?.velocity = CGVectorMake(0, 0)
Character.physicsBody?.applyImpulse(CGVectorMake(0, 15))
}
}
else{
//jump
Character.physicsBody?.velocity = CGVectorMake(0, 0)
Character.physicsBody?.applyImpulse(CGVectorMake(0, 15))
}
}
}
}
}
//states
func pauseState(){
pauseButton.hidden = true //hide pauseButton
self.physicsWorld.speed = 0 //pause physics (character, etc)
gameLayer.paused = true //pause gameLayer
self.addChild(pauseLayer) //add pauseLayer
}
func playState(){
pauseLayer.removeFromParent() //remove pauseLayer
gameLayer.paused = false //unpause gameLayer
self.physicsWorld.speed = 1 //unpause physics (character, etc)
pauseButton.hidden = false //show pauseButton
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1にアクセスしてクラッシュをデバッグする方法を学びます。 – rmaddy