I have this system for my sprites to allow them to be touch dragged:
Is touching Sprite ] Set sprite position to (touch.X, touch.Y)
It works, but it's not pretty. Basically, the centre point of the sprite jumps to your finger. I'd like to be able to drag from any part of the sprite and not have it jump/snap. Any ideas?
the centre is probably snapping to the finger because thats where the origin point is, is it possible to set an origin point for each corner say and then pick the closest one for dragging?
Develop games in your browser. Powerful, performant & highly capable.
There a quite a few sprites for that. I was thinking of something like: Get the difference between touch co-ords and sprite centre. Then put that at the touch co-ords.
Create 2 instance variables called grabX and grabY
On touch (or click):
set grabX to sprite.X-touch.X
set grabY to sprite.Y-touch.Y
Every tick (if being dragged):
Set the position to Touch.X+Sprite.grabX,Touch.Y+Sprite.grabY
Good luck <img src="smileys/smiley2.gif" border="0" align="middle">
PS: see my earlier created example here.
Perfect. Thanks Jasper