global gSnapped
property spritenum, pDropRange, pMagnetic, pOriginalLoc
on mouseUp me -- you have dropped the sprite
gSnapped = 0 -- this is a global flag, set to 1 if the dragged sprite is SNAPPED!
x = sprite(spritenum).loch -- horizontal dropzone
y = sprite(spritenum).locv -- vertical dropzone
sendAllSprites (#areYouNear, x, y, spritenum, pDropRange, pOriginalLoc) -- check to see if anyone is near
if gSnapped = 0 then sprite(spriteNum).loc = pOriginalLoc -- if no-one is, put me back!
end
on mouseDown me
pOriginalLoc = sprite(SpriteNum).loc -- record the original position
end
on areYouNear me ,x, y, spriteNumber, SnapRange, SendBack
if spriteNumber = spritenum then exit -- to avoid dropping it on my own head!!
if abs(sprite(spriteNum).loch - x) < SnapRange and abs(sprite(spriteNum).locv - y) < SnapRange then -- if i am near someone
if pMagnetic = 1 then -- check to see if they are sticky!
sprite(spritenumber).loc = sprite(spritenum).loc -- if they are, stick me to their loc
gSnapped = 1 -- and set the snapped flag
end if
end if
end
on getBehaviorDescription me
return("Put this behaivour on the sprite you want to drag, and on the sprite you want it to snap to."&& RETURN &¬
"You specify the distance it snaps from, and to define a sprite "snappable" use magnetic = true")
end
on getPropertyDescriptionList me
vPDList = [:]
setaProp vPDList, #pDropRange, [#comment: "Snap Range (pixels)",
#format: #integer, #default: 30,
#range: [#min: 0, #max: 100]]
setaProp vPDList, #pMagnetic, [#comment: "Magnetic?",
#format: #boolean, #default: 1]
return vPDList
end getPropertyDescriptionList
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA