cuốn sách gpt4 ai đã làm

swift - 使用 Swift 在 Scenekit 中移动相机

In lại Tác giả: Walker 123 更新时间:2023-11-28 07:52:56 26 4
mua khóa gpt4 Nike

我想在 Scenekit 的 z 轴上自动移动相机的每一帧。我用 Swift 写了这段代码:

func renderer(_ renderer: SCNSceneRenderer,
updateAtTime time: TimeInterval) {
cameraNode.position.z = cameraNode.position.z + 2
}

这仅适用于 3 帧,之后相机不再移动。有人可以给我正确的代码,以便相机每帧自动移动吗?

câu trả lời hay nhất

根据 SceneKit documentation :

SceneKit calls this method exactly once per frame, so long as the SCNView object (or other SCNSceneRenderer object) displaying the scene is not paused.

如果您的 View 中没有其他任何东西在移动,则场景“暂停”并且不会渲染。根据this question ,为了强制渲染每一帧,解决方法应该是:

sceneView.loops = true

但是,每帧都更新位置并不是最佳做法,因为 FPS 会发生变化,这会影响相机速度。但是您可以在不使用渲染功能的情况下使用 SCNAction 保持一致的相机速度:

let move = SCNAction.moveBy(x: 0, y: 0, z: 120, duration: 1.0)
let moveForever = SCNAction.repeatActionForever(move)
cameraNode.runAction(moveForever)

如果需要停止,这也将使您更容易控制相机,并且在不必要时不会强制渲染。

关于swift - 使用 Swift 在 Scenekit 中移动相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49223586/

26 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress