How do I mode several sprites while drag one

Just started using Construct 2? Post your questions here

Post » Wed Mar 15, 2017 7:34 pm

I am using the drag and drop behavior in a sprite and I would like to move 3 other sprites at the same time when I drag it. I tried to pin them to the main sprite and also the "every tick" condition to set their positions, but these tries don't work. Is it possible?
B
4
S
2
Posts: 125
Reputation: 850

Post » Wed Mar 15, 2017 8:06 pm

Use one or the other, not both.

(In reference to the pin behavior and setting position manually)
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Wed Mar 15, 2017 11:11 pm

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Mar 15, 2017 11:47 pm

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?
B
4
S
2
Posts: 125
Reputation: 850

Post » Thu Mar 16, 2017 2:05 pm

You add the distance that the main sprite moved/tick to the X&Y of the other objects while dragging the mainsprite.

Is dragging
_____ set any object's position to x= object.x + drag.dx ... y= object.y + drag.y
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Mar 16, 2017 11:48 pm

It worked very well. Thank you. @99Instances2Go!
B
4
S
2
Posts: 125
Reputation: 850


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests