6 posts
• Page **1** of **1**

set their positions, but these tries don't work

That is probably because you use 'world' coordinates. While you need 'relative' coordinates.

So first you find the X/Y pixels the dragged one moved compared to last tick.

Say dragged one's name = drag

2 instance variables. dx and dy. Their expressions are drag.dx and drag.dy.

2 instance variables. prex and prey. Their expressions are drag.prex and drag.prey.

Every tick

______ set (drag) dx to drag.x - drag.prex <---------- calculate difference

______ set (drag) dy to drag.y - drag.prey

______ set (drag) prex to drag.x <---------- update to use for the next tick

______ set (drag) prey to drag.y

Now, dx and dy hold the distance drag moved compared to the previous tick.

So ..

On dragging

_____ set any object's position to x= object.x + drag.dx ... y= object.y + drag.y

That is probably because you use 'world' coordinates. While you need 'relative' coordinates.

So first you find the X/Y pixels the dragged one moved compared to last tick.

Say dragged one's name = drag

2 instance variables. dx and dy. Their expressions are drag.dx and drag.dy.

2 instance variables. prex and prey. Their expressions are drag.prex and drag.prey.

Every tick

______ set (drag) dx to drag.x - drag.prex <---------- calculate difference

______ set (drag) dy to drag.y - drag.prey

______ set (drag) prex to drag.x <---------- update to use for the next tick

______ set (drag) prey to drag.y

Now, dx and dy hold the distance drag moved compared to the previous tick.

So ..

On dragging

_____ set any object's position to x= object.x + drag.dx ... y= object.y + drag.y

**Posts:**2,493**Reputation:**21,450

B

33
S

18
G

29
99Instances2Go wrote:set their positions, but these tries don't work

That is probably because you use 'world' coordinates. While you need 'relative' coordinates.

So first you find the X/Y pixels the dragged one moved compared to last tick.

Say dragged one's name = drag

2 instance variables. dx and dy. Their expressions are drag.dx and drag.dy.

2 instance variables. prex and prey. Their expressions are drag.prex and drag.prey.

Every tick

______ set (drag) dx to drag.x - drag.prex <---------- calculate difference

______ set (drag) dy to drag.y - drag.prey

______ set (drag) prex to drag.x <---------- update to use for the next tick

______ set (drag) prey to drag.y

Now, dx and dy hold the distance drag moved compared to the previous tick.

So ..

On dragging

_____ set any object's position to x= object.x + drag.dx ... y= object.y + drag.y

Thanks @99Instances2Go

Sorry, but this is a little confusing for me.

I have a main Sprite (that I think you named as "drag") with the drag 'n drop behavior so I need to create these 4 variables in this sprite and in the event "on dragging" I will associate all the other objects (or a family) that I need that follow the main sprite. Is it right?

**Posts:**153**Reputation:**908

B

4
S

2
6 posts
• Page **1** of **1**

Return to Beginner's Questions

## Who is online |

Users browsing this forum: No registered users and 2 guests |