Touch Drag Jump

Get help using Construct 2

Post » Sat Jan 26, 2013 8:33 pm

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?
B
19
S
3
G
2
Posts: 212
Reputation: 4,011

Post » Sat Jan 26, 2013 8:46 pm

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?
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Sat Jan 26, 2013 8:58 pm

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.
B
19
S
3
G
2
Posts: 212
Reputation: 4,011

Post » Sat Jan 26, 2013 9:45 pm

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

PS: see my earlier created example here.Jasper2013-01-26 22:03:26
B
13
S
3
G
4
Posts: 35
Reputation: 3,358

Post » Sat Jan 26, 2013 10:12 pm

Perfect. Thanks @Jasper
B
19
S
3
G
2
Posts: 212
Reputation: 4,011


Return to How do I....?

Who is online

Users browsing this forum: fredriksthlm, MPPlantOfficial and 21 guests