In the touchesMoved method, what is the math to have an object on the screen move along a dragging touch vector? For instance, if I touch beneath my object (Y > object.y), and drag “up”, I want the object to move from its current x,y location along the same vector that my finger moves.
Currently I have it working that the drag motion snaps my object to my finger’s location, but sometimes my finger hits the edge of the screen before I get my object positioned correctly.
If I know my “touch down location” and the “current touch location” what is the math to determine where to move object.position?
I hope that you have already received the answer of figured it out yourself, but.
Assume that your object’s Upper Left Corner (ULC) is at
Object.X,ObjectY.Assume that the
CGPointreturned bytouchsBeganisTouch.X,Touch.Y.The offset (Delta) will be:
Delta.X = Touch.X - Object.XDelta.Y = Touch.Y - Object.XSubtract these from each point returned by
touchesMovedand your ULC should move as you expect rather than snapping to your finger.Good luck.