Move a group in whilst moving an object in the group

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 184
Joined: Wed Apr 10, 2013 5:09 pm

Move a group in whilst moving an object in the group

Post by andrewferguson » Mon Sep 29, 2014 4:09 pm

Hi all,
I have a group of objects, and I want to move this group along the horizontal axis. At the same time, I also want an object that is in the group to move along the vertical axis whilst still moving with the rest of the group.

I know of a more complicated way that involves calculating where the object will be on the x and y axis once the move has finished, but I am hoping that there is an easier way.

Any ideas?

Thanks,
Andrew

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Move a group in whilst moving an object in the group

Post by zaxos » Mon Sep 29, 2014 5:04 pm

Code: Select all

on scrollGroup
  set the lockLoc of group "YourGroup" to true
  set the left of group "YourGroup" to (the left of this card - 1)
  set the left of btn "YourObject" to (the left of group "YourGroup)
  send "scrollGroup" to me in 25 milliseconds
end scrollGroup
a better way would be to put your group inside another group

Code: Select all

on scrollGroup
  set the lockLoc of group "YourGroup" to true
  set the lockLoc of group "YourGroup2" to true
  set the left of group "YourGroup" to (the left of group "YourGroup2"- 1)
  set the left of btn "YourObject" to (the left of group "YourGroup)
  send "scrollGroup" to me in 25 milliseconds
end scrollGroup
Knowledge is meant to be shared.

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

Re: Move a group in whilst moving an object in the group

Post by dunbarx » Mon Sep 29, 2014 7:37 pm

Hi.

Not sure whether you are moving under script control. or via the mouse, or whatever. But if under script control, then with several objects grouped, one of which is a button named "b1", put this into the script of another, independent button:

Code: Select all

on mouseUp
   set the startprop of grp 1 to the properties of grp 1
   set the startloc of btn 1 to the loc of btn 1
   repeat 100
      set the left of grp 1 to the left of grp 1 + 1
      set the top of btn 1 to the top of btn 1 + 1
      wait 2
   end repeat
   set the properties of grp 1 to the startprop of grp 1
      set the loc of btn 1 to the startloc of btn 1
end mouseUp
Move the test group to the left side of the card window. Click on the independent button. Does this help? Do you see what the set-up and clean-up lines do?

Craig Newman

Post Reply