As you can see in the last two lines of the code below, I specify a specific SKSpriteNode to get the correct (or is it, adjusted?) touch coordinates. The last line is just left in there to compare while I am debugging.
I was curious if there was already a method in Swift that translates any coordinates handed to it into physical screen coordinates?
It would just be easier than having to first find out: Is this item that I am tracking, owned by the main GameScene, or a SKSpriteNode that has been placed somewhere other than 0,0 on the GameScene?
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches , with:event)
var delta = CGPoint(x: 0, y: 0)
guard touches.first != nil else { return }
if let touch = touches.first,
let node = myGV.currentGem,
node.isMoving == true {
let touchLocation = touch.location(in: myGV.guessBar!)
let touchLocation2 = touch.location(in: self)
If you find the topmost view (calling superview repeatedly) then
let touchLocationAbsolute = touch.location(in: topMostView)
will give you what you are looking for.
To find the topmost, I would do something like this :
var topMostView = myGV.guessBar
var upperView = myGV.guessBar
while upperView != nil {
topMostView = upperView!
upperView = topMostView!.superview
}
let touchLocationAbsolute = touch.location(in: topMostView)