GameSceneを最初に作成して動作しましたが、今度はMainMenuシーンを追加しようとしています。ゲームを開始すると、上記のエラーが表示されます。別のシーンから呼び出したときに「オプション値をアンラッピングしている間に無意味な値が見つかりませんでした」
GameViewControllerは、Appleのコードであり、MainMenuシーンでアプリを起動しますが、GameViewControllerでGameSceneを実行しているアプリをテストしましたが、エラーは発生しませんが、メインメニューはありません。
GameScene内:
var UpperLeft = SKSpriteNode()
var BottomRight = SKSpriteNode()
var UpperRight = SKSpriteNode()
var BottomLeft = SKSpriteNode()
var Ball = SKSpriteNode()
エラーは、私がアンラップするために強制していた各1である↓
override func didMove(to view: SKView) {
scoreLabel = self.childNode(withName:"scoreLabel") as! SKLabelNode
UpperLeft = self.childNode(withName:"UpperLeft") as! SKSpriteNode
BottomRight = self.childNode(withName:"BottomRight") as! SKSpriteNode
UpperRight = self.childNode(withName:"UpperRight") as! SKSpriteNode
BottomLeft = self.childNode(withName:"BottomLeft") as! SKSpriteNode
Ball = self.childNode(withName:"Ball") as! SKSpriteNode
私はエラーがから来ていることを理解
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
if let scene = SKScene(fileNamed: "mainMenu") {
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
view.ignoresSiblingOrder = true
// Present the scene
view.presentScene(scene)
}
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}
:GameViewController以内
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
if let location = touches.first?.location(in: self) {
let touchedNode = atPoint(location)
if touchedNode.name == "StartGame" {
let transition = SKTransition.reveal(with: .down, duration: 1.0)
let nextScene = GameScene(size: scene!.size)
nextScene.scaleMode = .aspectFill
scene?.view?.presentScene(nextScene, transition: transition)
}
}
}
:0
エラーがそれぞれ、私はメインメニュー内
↑アンラップするために強制的にだ1でありますとして!アンラップを強制しますが、mainMenuシーンからGameSceneを呼び出すとこれが問題になるのはどうですか?私はアンラップごとにオブジェクトを作成したので、それらはゼロではありませんか?代わりに、メインメニューで使用されるものの
let nextScene = GameScene(fileNamed: "GameScene")
:
あなたのコードをテキスト形式の質問に直接投稿してください。また、エラーの原因となった行を指摘します。 –
[任意の値をアンラッピングしている間に "致命的なエラーが予期せず見つからない"とはどういう意味ですか?](http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil- while-unwrap-an-optional-valu) – rmaddy
'as!'は型変換を強制し、変換が不可能な場合はランタイムエラーで失敗します。これは表示されている強制アンラップエラーです。 – BallpointBen