作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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”是我在资源/文件部分中的一个文件及其纹理,如果没有任何与月球相关的代码,我仍然有问题。)
最佳答案
关于swift - 如何解决 Swift Playgrounds 中的 “There was a problem running this page” 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61785346/
我是一名优秀的程序员,十分优秀!