gpt4 book ai didi

inheritance - SceneKit Swift 3 继承不起作用

转载 作者:行者123 更新时间:2023-12-02 11:00:27 25 4
gpt4 key购买 nike

我写了一个类:

import UIKit
import SceneKit

class Scene: SCNScene {

var _sceneView: SCNView!
var cameraNode: SCNNode!

func setupView(view: SCNView) {

_sceneView = view

}
}

但是当我在 GameViewController 中调用该类的函数时:
import UIKit
import QuartzCore
import SceneKit
import SpriteKit

class GameViewController: UIViewController, SCNSceneRendererDelegate {

var scene: Scene? = nil

override func viewDidLoad() {

super.viewDidLoad()

//Super
super.viewDidLoad()

scene = Scene()

let sceneView = self.view as! SCNView

...

sceneView.scene = scene?.setupView(view: sceneView)
}
}

它显示错误:

无法分配“()”类型的值?输入“SCNScene?”

当我试图调用函数时,它被划掉了函数:

crossed-out function

请解释并帮助解决该问题。

提前致谢。

最佳答案

忽略其他潜在问题(除非绝对需要,否则不要强制解包( ! ),下划线变量名是objective-c ivars的约定,有时用于命名swift类的私有(private)存储),你可能想要的是类似于:

//: Playground - noun: a place where people can play

import UIKit
import SceneKit
import QuartzCore
import SpriteKit

class Scene: SCNScene {

var _sceneView: SCNView!
var cameraNode: SCNNode!

func setupView(view: SCNView) {

_sceneView = view

}
}

class GameViewController: UIViewController, SCNSceneRendererDelegate {

var scene: Scene? = nil

override func viewDidLoad() {
super.viewDidLoad()

let scene = Scene()

let sceneView = self.view as! SCNView
scene.setupView(view: sceneView)
sceneView.scene = scene

self.scene = scene
}
}

关于inheritance - SceneKit Swift 3 继承不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43260616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com