How do I mode several sprites while drag one

0 favourites
  • 6 posts
From the Asset Store
Several elements of the game interface hidden objects
  • 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?

  • Use one or the other, not both.

    (In reference to the pin behavior and setting position manually)

  • 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

  • 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?

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It worked very well. Thank you. 99Instances2Go!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)