Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sprite kit WatchKit在展开可选值时,从另一个意外发现的nil中显示SKScene_Sprite Kit_Watchkit_Apple Watch_Watchos 3 - Fatal编程技术网

Sprite kit WatchKit在展开可选值时,从另一个意外发现的nil中显示SKScene

Sprite kit WatchKit在展开可选值时,从另一个意外发现的nil中显示SKScene,sprite-kit,watchkit,apple-watch,watchos-3,Sprite Kit,Watchkit,Apple Watch,Watchos 3,我想在我的WatchKit应用程序中呈现另一个SKScene中的SpriteKit场景。 这是我的密码: class GameScene: SKScene, SKPhysicsContactDelegate { var scene2: Scene2! @IBOutlet var skInterface: WKInterfaceSKScene! override func sceneDidLoad() { physicsWorld.contactDelegate = self ....

我想在我的WatchKit应用程序中呈现另一个SKScene中的SpriteKit场景。 这是我的密码:

class GameScene: SKScene, SKPhysicsContactDelegate {
var scene2: Scene2!
@IBOutlet var skInterface: WKInterfaceSKScene!
override func sceneDidLoad() {
    physicsWorld.contactDelegate = self
 ....
 changeScene()

 }
func changeScene() {
if let scene = Scene2(fileNamed: "Scene2") {

        scene2 = scene


        scene.scaleMode = .aspectFill


        self.skInterface.presentScene(scene)


        self.skInterface.preferredFramesPerSecond = 30
    }
} 但当我试图呈现另一个场景时,我得到了以下错误:

   "fatal error: unexpectedly found nil while unwrapping an Optional value" 

如何解决这个问题?

你的SkinInterface就是nilok,这很清楚…那么我如何从游戏场景中加载SKscene?与其将SkinInterface作为IBOutlet,不如将其作为常规变量,并在你的视图控制器中,当你最初呈现场景时,之后分配变量。我为游戏场景做了这个…在InterfaceController中声明并从中加载。但现在我必须从游戏场景本身加载这个新场景。你的SkinInterface就是nilok,这很清楚…那么我如何从我的游戏场景加载SKscene呢?与其将SkinInterface作为IBOutlet,不如将其作为常规变量,并在你的视图控制器中,当你最初呈现场景时,之后分配变量。我为游戏场景做了这个…在InterfaceController中声明并从中加载。但现在我必须从游戏场景本身加载这个新场景。