Drag just the top object (without drag n drop behavior)

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I'm making a custom drag n drop behavior with events, without using the built-in behavior that is very limited. I'm using physics and the touch object. Everything is working fine, except for one thing:

    I disabled collisions between the draggable objects, so they can overlap each other. And here is the problem... when there is more than one draggable objects overlapping each other, if I click to drag, everyone is activated, not just the top one. And it is different sprites, not just different instances of the same... so I just can't figure out how to work around that.

    How can I manage to fix this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm guessing you have different events for different sprites?

    Mouse -> On Sprite1 clicked -> (start dragging Sprite1)

    Mouse -> On Sprite2 clicked -> (start dragging Sprite2)

    etc.

    Just create a flag (a global variable) isDragging. Set isDragging=1 when a sprite is clicked, reset to 0 when it's dropped.

    Add a second condition to all these events:

    System-> isDragging=0

    Or if all these draggable sprites are in a family, and you have just one event (Mouse->On DraggableFamily clicked), add DraggableFamily->Pick Top Instance as a sub-event.

  • I'm guessing you have different events for different sprites?

    Mouse -> On Sprite1 clicked -> (start dragging Sprite1)

    Mouse -> On Sprite2 clicked -> (start dragging Sprite2)

    etc.

    Just create a flag (a global variable) isDragging. Set isDragging=1 when a sprite is clicked, reset to 0 when it's dropped.

    Add a second condition to all these events:

    System-> isDragging=0

    Or if all these draggable sprites are in a family, and you have just one event (Mouse->On DraggableFamily clicked), add DraggableFamily->Pick Top Instance as a sub-event.

    Yeah!

    It worked very well

    Thank you!

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