Having strange trouble with touchesMoved, need help.

Am trying to make a game, where I drag gems around.

The hierarchy is:

GameScene (this is the view controller)
gemBase, which holds the gems (light grey) SKSpriteNode
gems SKSpriteNode

The gems are children of gemBase, which is a child of GameScene.

When the gemBase is at 0,0 everything works fine when I drag the gems. They are in the same place I am touching the screen. But I want to offer a left-handed feature, where I offset the gemBase to the rightsize of the screen. All gems automatically move with the base so I don't need to recalculate their positions.

But then, when I try to move the gems, they are offset to the right of where I am touching the screen. They are offset by as much as I move the gemBase.

Below is my only code where I handle touchesMoved (in GameScene)

If you're having problems visualizing what I am describing, the screen shot is at:

http: // 98.7.37.117/ss.gif

Do I have to convert the touch.location?

Code Block
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
        guard touches.first != nil else { return }
        if toggleHigh {highliteGem(theGem: myGems[0], clearAll: true)}
        if let touch = touches.first, let node = myGV.currentGem, node.isMoving == true {
            let touchLocation = touch.location(in: self)
            node.moved    = true
            node.position = touchLocation
            node.isMoving = true
            node.inSlot = false
            //addTrailToTwinkle(theNode: node)
        }
    }

Answered by SergioDCQ in 674796022
I got the answer over at Stack overflow,

https://stackoverflow.com/questions/67511055/having-a-strange-trouble-with-touchesmoved-position-doesnt-match-location-wher?noredirect=1#comment119406263_67511055

Someone took the time to recreate my issue and had me change:

Code Block
let touchLocation = touch.location(in: self) 

to
Code Block
let touchLocation = touch.location(in: gemBase)


Of course that leads me to another question, but I'll start another thread for that.
By moving gemBase to the middle, rather than all the way left, the gap between where I touch the screen and how far off to the right the gem is, is less.

So is this because the gems are owned by gemBase? If so not sure why this what the solution is
You don't call super.touchesMoved.
Try to add it at beginning.

Do you override all the other touches func ?

Apple doc says:
If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.
I cannot access the URL, (after removing the spaces)

I cannot access the URL, (after removing the spaces)

All of a sudden FileZilla won't properly transfer images at all (yes, set to binary). Looking for a new FTP.

Have added super. to all my touches (as seen below) and it still happens


Code Block
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
        super.touchesMoved(touches , with:event)
        guard touches.first != nil else { return }
        if toggleHigh {highliteGem(theGem: myGems[0], clearAll: true)}
        if let touch = touches.first, let node = myGV.currentGem, node.isMoving == true {
            let touchLocation = touch.location(in: self)
            node.moved    = true
            print(touchLocation)
            node.position = touchLocation
            node.isMoving = true
            node.inSlot = false
            //addTrailToTwinkle(theNode: node)
        }
    }

I cannot access the URL, (after removing the spaces)

Finally got the screenshot up there

http:// 98.7.37.117/screen.gif
OK, now we get the screenshots.
But some explanation of what each picture is would help.

Also some questions on your code:
Code Block
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
super.touchesMoved(touches , with:event)
guard touches.first != nil else { return }
if toggleHigh {highliteGem(theGem: myGems[0], clearAll: true)}
if let touch = touches.first, let node = myGV.currentGem, node.isMoving == true {
let touchLocation = touch.location(in: self)
node.moved = true
print(touchLocation)
node.position = touchLocation
node.isMoving = true
node.inSlot = false
//addTrailToTwinkle(theNode: node)
}
}

In which class is this ? ie, what is self ?
do we see effect of toggleHeight in the pictures of the gif ?
line 10: we get there only when isMoving. So what the need ?
what is the result of the print ? Is it what you expect ?

In which class is this ? ie, what is self ?

GameScene

toggleHigh, line 10, isMoving

That's misc, and a copy error. All the other code be removed and it's the same thing

what is the result of the print ? Is it what you expect ?

No it's not, that's the problem. So if I move the gemBase, which is its own class) to the right by let's say 100. Then the print result is 100 more than where I'm touching on the screen. That's why I wondered this is due to the gem being owned by the gemBase.


Accepted Answer
I got the answer over at Stack overflow,

https://stackoverflow.com/questions/67511055/having-a-strange-trouble-with-touchesmoved-position-doesnt-match-location-wher?noredirect=1#comment119406263_67511055

Someone took the time to recreate my issue and had me change:

Code Block
let touchLocation = touch.location(in: self) 

to
Code Block
let touchLocation = touch.location(in: gemBase)


Of course that leads me to another question, but I'll start another thread for that.
Having strange trouble with touchesMoved, need help.
 
 
Q