Moving an object smoothly while sending messages
Posted: Thu Jun 27, 2013 3:12 pm
So I have a graphic of which I wish to move automatically upon mouseup to the side of the stack. This is easy with the move function. However, I need to send messages along the way or somehow get the group that is next to it to follow at the same speed and distance. The solution I came up with is to use a repeat with the total distance divided into 50 segments, then set the graphic to move in 50 small increments while sending the message that moves the group according to the graphic. This works, but every time I simulate it, it ends up in a different place. I checked the variables and I believe that this is due to Livecode rounding the variable distance number to 2 decimal places for its calculation. I don't think that is accurate enough to get the graphic objects to align correctly after 50 moves.
Here is a really chunky and sloppy written code of what I am trying to do because I am still formulating new methods and am not quite sure what I need yet.
But my main question is, is there a smoother, more accurate way to go about this?
Here is a really chunky and sloppy written code of what I am trying to do because I am still formulating new methods and am not quite sure what I need yet.
But my main question is, is there a smoother, more accurate way to go about this?
Code: Select all
on mouseup
##find the x location of the mouse (the graphic only scrolls left and right)
put the mouseloc into tMouseLoc
put item 1 of tMouseLoc into xMouseLoc
##spacing on the side
put (the left of field "contact name" of this card + (the width of grc "slider bar" of this card/2)) into tVarWidth
##get the location of the graphic into separate variables for easy calc
put the location of me into tMeLoc
put item 2 of tMeLoc into yMeLoc
put item 1 of tMeLoc into xMeLoc
##I think this line of code made it jump to 3 decimal places but did not help
set the numberFormat to "#.00000"
put ((the left of graphic "slider bar" of this card)-(the left of field "contact name" of this card))/50 into tInterval
if the left of grc "slider bar" of this card < (the width of this stack * 0.5) then
repeat with x = 1 to 50
set the left of me to (the left of me - tInterval)
##moveControl sets a group's location according to the location of the graphic
moveControl
end repeat
##I put this here to correct any differences at the end but it does not work that well
if the left of grc "slider bar" of this card <> the left of the field "contact name" of this card then
set the left of grc "slider bar" of this card to the left of the field "contact name" of this card
moveControl
end if
##This is a repeat of the above if statement for the right side
else if the right of grc "slider bar" of this card >= (the width of this stack * 0.5) then
put true into gAllowMove
repeat with x = 1 to 50
set the left of me to (the left of me + tInterval)
moveControl
end repeat
if the right of grc "slider bar" of this card <> the right of the field "sort list" of this card then
set the right of grc "slider bar" of this card to the right of the field "sort list" of this card
moveControl
end if
else
exit mouseup
end if
put false into gAllowMove
end mouseup