处理触摸动作以便将多个对象添加到场景的最佳方式是什么?
What's the best way to handle touch actions in order to add multiple objects to a scene?
我想在一个场景中添加多个对象,但我似乎无法理解如何访问具有 touches: Set<UITouch>
的集合的不同的、无序的位置
是否有更有效的方法来处理在每次特定屏幕触摸后一次添加一个对象请求?
添加一个手势识别器,获取(点击的)currentLocation,然后un-project 2D 屏幕坐标到 3D 世界 space。 scenePoint 包含您需要的矢量。如果您向下看 -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)
}
}
我想在一个场景中添加多个对象,但我似乎无法理解如何访问具有 touches: Set<UITouch>
是否有更有效的方法来处理在每次特定屏幕触摸后一次添加一个对象请求?
添加一个手势识别器,获取(点击的)currentLocation,然后un-project 2D 屏幕坐标到 3D 世界 space。 scenePoint 包含您需要的矢量。如果您向下看 -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)
}
}