Page 1 of 1
How to not allow an graphic drag through another object?
Posted: Sat Apr 12, 2008 3:29 pm
by alex298
Hi,
I have two graphics (a ball and a wall) on a card. The user can use the mouse to drag around the card but not allow to drag across the wall.
I tried to use mousedown and drag, intersect and within. However the ball can be dragged through the wall. I studied some similar examples on the Web, they just used a beep sound to alert the intersection. The two objects can be intersected and overlapped.
I need the two objects not allow to overlap, just touching. How can I do that?
Thanks and best regards
Posted: Sun Apr 13, 2008 9:34 am
by Mark
Hi Alex,
The following script comes from my Snapper project <
http://snapper.economy-x-talk.com>, which has a selection area that does something similar to what you need. To try this script, you'll need an object, e.g. a transparent button, containing this script and an image named "Selection". After you have figured out how this script wors, you should be able to do what you want.
Code: Select all
on mouseDown
put the mouseLoc into myLoc
set the cursor to cross
repeat until the mouse is up
put the mouseLoc into myNewLoc
put quadrant(myLoc,myNewLoc)
switch quadrant(myLoc,myNewLoc)
case 1
put item 1 of myLoc & comma & item 2 of myNewLoc into myTL
put item 1 of myNewLoc & comma & item 2 of myLoc into myBR
break
case 2
put myLoc into myBR
put myNewLoc into myTL
break
case 3
put item 1 of myLoc & comma & item 2 of myNewLoc into myBR
put item 1 of myNewLoc & comma & item 2 of myLoc into myTL
break
case 4
put myLoc into myTL
put myNewLoc into myBR
break
end switch
if item 1 of myBR > the right of me then put the right of me into item 1 of myBR
if item 2 of myBR > the bottom of me then put the bottom of me into item 2 of myBR
if item 1 of myTL < the left of me then put the left of me into item 1 of myTL
if item 2 of myTL < the top of me then put the top of me into item 2 of myTL
put myTL & comma & myBR into myRect
if myRect is a rect then
set the rect of grc "Selection" to (myTL & comma & myBR)
end if
end repeat
set the cursor to arrow
end mouseDown
function quadrant theOldLoc,theNewLoc
if item 1 of theNewLoc > item 1 of theOldLoc and item 2 of theNewLoc < item 2 of theOldLoc then
return 1
else if item 1 of theNewLoc< item 1 of theOldLoc and item 2 of theNewLoc < item 2 of theOldLoc then
return 2
else if item 1 of theNewLoc < item 1 of theOldLoc and item 2 of theNewLoc > item 2 of theOldLoc then
return 3
else if item 1 of theNewLoc > item 1 of theOldLoc and item 2 of theNewLoc > item 2 of theOldLoc then
return 4
end if
return 0
end quadrant
Best regards,
Mark Schonewille