[英]Why is my Scene null?
我試圖做一些JavaFX的3D工作(使用TornadoFX庫),但無法設置我PerspectiveCamera
到Scene
的Scene
將返回null
。
我像這樣啟動程序:
class ThreeDTest : App(HomeView::class, ThreeDStyles::class) {
override fun start(stage: Stage) {
super.start(stage)
stage.show()
stage.scene.fill = Color.BLACK
val primaryScreenBounds = Screen.getPrimary().visualBounds
stage.maxWidth = 1920.0
stage.maxHeight = 1080.0
stage.minWidth = 1920.0
stage.minHeight = 1080.0
}
}
然后在HomeView
類中,我有這個:
class HomeView : View() {
override val root = stackpane {
val axisGroup = Xform()
val world = Xform()
val camera = PerspectiveCamera(true)
val cameraXform = Xform()
val cameraXform2 = Xform()
val cameraXform3 = Xform()
val cameraInitialDistance = -450.0
val cameraInitialXAngle = 70.0
val cameraInitialYAngle = 320.0
val cameraNearClip = 0.1
val cameraFarClip = 10000.0
//just a builder class to add properties to the camera
buildCamera(this, cameraXform, cameraXform2, cameraXform3, camera, cameraNearClip, cameraFarClip, cameraInitialDistance,
cameraInitialYAngle, cameraInitialXAngle)
buildAxes(axisGroup, world)
println(scene)
//returns null
scene.camera = camera
//this does not work as scene is null
}
我做錯了什么嗎? 我不知道為什么我的Scene
為空,因為我以為TornadoFX View
應該在初始化時創建一個新Scene
? 我需要在App類中手動創建它嗎? 我嘗試覆蓋createPrimaryScene
函數,還嘗試將代碼移到HomeView
視圖中的init
函數,但都沒有成功。
有任何想法嗎? 在這里拔頭發。
(哦,沒有關系的話,我可以說坦白地說,在TornadoFX中提供3D支持將使我畢生難忘嗎?)
View是在附加場景之前創建的,因此要操作場景,只需覆蓋onDock
並在其中執行操作即可。 調用onDock
,將附加場景。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.