gpt4 book ai didi

swift - 如何解决 Swift Playgrounds 中的 “There was a problem running this page” 消息?

转载 作者:行者123 更新时间:2023-12-03 16:35:18 25 4
gpt4 key购买 nike

我正在尝试使用 SceneKit 为 WWDC 学生挑战赛做一些事情,这要求我的项目在 Swift 游乐场中。我不断收到“运行此页面时出现问题”的消息。它不提供错误消息。它只是建议检查我的代码或重新开始。我曾尝试单独删除代码段,但找不到此问题的根源。我还尝试在 man Xcode playground 中运行它,它提供了警告,我引用“操场无法继续运行,因为操场源代码做到了”。我被困住了。我的代码有什么问题。

import UIKit
import SceneKit
import QuartzCore
import PlaygroundSupport

class GameScene: UIViewController, SCNSceneRendererDelegate {
var primaryView: SCNView!
var primaryScene: SCNScene!
var cameraNode: SCNNode!

override func viewDidLoad() {
sceneAndViewInit()
cameraInit()
createGround()
moonInit()
}

func createGround() {
var ground = SCNBox(width: 200, height: 1, length: 200, chamferRadius: 0)
var groundPhysicsShape = SCNPhysicsShape(geometry: ground, options: nil)
var groundNode = SCNNode(geometry: ground)
ground.firstMaterial?.diffuse.contents = UIColor.orange
ground.firstMaterial?.specular.contents = UIColor.white
groundNode.position = SCNVector3(0, -6, 0)
groundNode.physicsBody = SCNPhysicsBody(type: .static, shape: groundPhysicsShape)
primaryScene.rootNode.addChildNode(groundNode)
}

func sceneAndViewInit() {
primaryView = SCNView(frame: CGRect(x: 0, y: 0, width: 500, height: 300))
primaryView.allowsCameraControl = true
primaryView.autoenablesDefaultLighting = true

primaryScene = SCNScene()

primaryView.scene = primaryScene
primaryView.isPlaying = true
}

func cameraInit() {
var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 2)
cameraNode.camera?.fieldOfView = 65
cameraNode.camera?.wantsHDR = false
primaryScene.rootNode.addChildNode(cameraNode)
}

func moonInit() {
let moonScene = SCNScene(named: "Moon.scn")
var moonNode = moonScene?.rootNode.childNode(withName: "Sphere", recursively: true)
var moonPhysicsShape = SCNPhysicsShape(node: moonNode!, options: nil)
moonNode?.position = SCNVector3(0, 0, 0)
moonNode?.scale = SCNVector3(1, 1, 1)
moonNode?.name = "Moon"
moonNode?.physicsBody = SCNPhysicsBody(type: .static, shape: moonPhysicsShape)
primaryScene.rootNode.addChildNode(moonNode!)
}

func renderer(_ aRenderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
print(time)
}
}

let gameScene = GameScene()
PlaygroundPage.current.liveView = gameScene
(“Moon.scn”是我在资源/文件部分中的一个文件及其纹理,如果没有任何与月球相关的代码,我仍然有问题。)

最佳答案

要查看完整的错误消息,请转到设置应用程序 -> Playgrounds -> 打开创作 Debug模式。这并不能直接解决问题,但它对定位错误更有帮助。
Settings app -> Playgrounds -> turn on Authoring Debug Mode

关于swift - 如何解决 Swift Playgrounds 中的 “There was a problem running this page” 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61785346/

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