Page 1 of 1

Dragging 2 objects together

Posted: Tue Oct 13, 2020 11:02 pm
by gsillevis
Hello!

I just started messing around today and I'm having a lot of fun. I'm making a puzzle game
Here is a screenshot
imgur[dot]com/IXoUCac

Each of the objects can be dragged around using

Code: Select all

on mousedown
grab me
end mousedown
That works fine. So, in this puzzle, the answer is Radboud. I have created a rectangle that, if clicked, takes the player to the correct card.

What I want is for the rectangle to drag along with the Painting Registry object. So that you can drag the Painting Registry around, and still if you click Radboud, it works. Does that make sense?

My first guess was to do

Code: Select all

on mousedown
grab me
grab rectangle "correctanswer"
end mousedown
but that didn't work. Any suggestions? Thank you!

Re: Dragging 2 objects together

Posted: Tue Oct 13, 2020 11:40 pm
by dunbarx
Hi.

"Grab" really cannot be extended to multiple controls. You have to fool LC just a little. On a new card make two buttons, Name one "B1" and the other "B2". In the script of B1:

Code: Select all

on mouseMove
   if the mouse is down then
      set the loc of me to the mouseLoc
      set the loc of btn "b2" to item 1 of the loc of me + 40 & "," & item 2 of the loc of me + 40 --arbitrary values of offset
   end if
end mouseMove
Click on B1 and hold the mouse down while you drag. You can add as many controls as you like.

Craig

Re: Dragging 2 objects together

Posted: Wed Oct 14, 2020 11:44 am
by gsillevis
Thanks for your reply! In the end, I just grouped the objects in the Project browser, removed the Grab script from the objects and applied them to the new group. Works like a charm!