处理触摸操作以向场景添加多个对象的最佳方法是什么?



我想向一个场景添加多个对象,但我似乎无法考虑如何访问具有touches: Set<UITouch>的集合的不同无序位置

有没有更有效的方法来处理每次特定屏幕触摸后一次添加一个对象请求?

添加手势识别器,获取(点击的(当前位置,然后将 2D 屏幕坐标取消投影到 3D 世界空间。 场景点包含您需要的矢量。 如果您向下看 -Z 轴,Y 向上,这将起作用。

var currentLocation = CGPoint.zero
 @objc func handleTap(recognizer: UITapGestureRecognizer)
        {
            currentLocation = recognizer.location(in: gameScene)
            let projectedPoint = gameScene.projectPoint(SCNVector3(0, 0, 0))
            let scenePoint = gameScene.unprojectPoint(SCNVector3(currentLocation.x, currentLocation.y, CGFloat(projectedPoint.z)))
            {
                placeObject(vPosition: scenePoint)
            }
        }

最新更新