I have a UIView that I want to position on top of a certain area in an SKScene.
This is the point that I have in my SKScene:
guard let point = elementCGPoints.centroid() else {
return
}
And I'm trying to use this SKView method to convert from scene coordinates to view coordinates; based on this SO discussion:
let convertedPoint = canvasScene.convertPoint(toView: point)
selectionBox.frame = CGRect(x: convertedPoint.x, y: convertedPoint.y, width: 100, height: 100)
However, this ends up always displaying at a point far beyond the range of my view.
Any intuition about how to do this right?
here are two ways. the first is responding to UITouch inside SKScene
this is easiest. but your question suggests you want to use
convertPointin which case you could convert an arbitrary point from scene to view like thisand the UIViewController delegate would look like this