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?
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) } }
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:
to
Of course that leads me to another question, but I'll start another thread for that.
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.