【发布时间】:2021-05-16 05:39:01
【问题描述】:
我正在尝试在我的 SceneKit 游戏中获取特定节点的 SCNVector3,以便我可以确定我的玩家在每一轮中如何与它们交互。我在玩家执行移动操作后运行此程序,但我的“可推送块”在 mapList 中的位置保持不变,即使它们位于游戏中的不同位置。
var mapList: [SCNNode] = []
func mapLocationSave() {
let pushableNode = self.gameScene.rootNode.childNode(withName: "Pushables", recursively: true)
let wallNodes = gameScene.rootNode.childNode(withName: "Boxes", recursively: true)
let coinNodes = gameScene.rootNode.childNode(withName: "Coins", recursively: true)
for pushNode in pushableNode!.childNodes {
mapList.append(pushNode)
}
for wallNode in wallNodes!.childNodes {
mapList.append(wallNode)
}
for coinNode in coinNodes!.childNodes {
mapList.append(coinNode)
}
for node in mapList {
print(node.name!, node.worldPosition)
}
}
我怀疑这是因为我没有使用当前游戏位置更新 mapList,而只是循环遍历 gameScene.scn 文件?
我在 Apple 文档中找不到任何关于如何在游戏节点中循环当前的文档。
【问题讨论】:
-
你在哪里调用 mapLocationSave() ?
-
在 viewDidLoad() 中,然后在玩家的每一个动作之后
-
self.gameScene 是如何定义的?
-
self.view.addSubview(scnView)scnView.scene = gameScene -
代替
self.gameScene.rootNode....试试scnView.scene.rootNode....