Dragging 2 objects together

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gsillevis
Posts: 40
Joined: Tue Oct 13, 2020 10:55 pm

Dragging 2 objects together

Post by gsillevis » Tue Oct 13, 2020 11:02 pm

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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: Dragging 2 objects together

Post by dunbarx » Tue Oct 13, 2020 11:40 pm

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

gsillevis
Posts: 40
Joined: Tue Oct 13, 2020 10:55 pm

Re: Dragging 2 objects together

Post by gsillevis » Wed Oct 14, 2020 11:44 am

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!

Post Reply