This behavior allows you to drag a sprite around the stage but confine it to the stage boundries.
--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
property spriteNum, clickOffset
on mouseDown me
clickOffset = sprite(spriteNum).loc - the mouseLoc
stageWidth = the stageRight- the stageLeft
stageHeight = the stageBottom - the stageTop
leftAdjust = sprite(spriteNum).locH - sprite(spriteNum).left
rightAdjust = sprite(spriteNum).locH - sprite(spriteNum).right
topAdjust = sprite(spriteNum).locV - sprite(spriteNum).top
bottomAdjust = sprite(spriteNum).locV - sprite(spriteNum).bottom
repeat while the stillDown
newLoc = the mouseLoc + clickOffset
if newLoc.locH > stageWidth + rightAdjust then
newLoc.locH = stageWidth + rightAdjust
else if newLoc.locH < 0 + leftAdjust then
newLoc.locH = 0 + leftAdjust
end if
if newLoc.locV > stageHeight + bottomAdjust then
newLoc.locv = stageHeight + bottomAdjust
else if newLoc.locV < 0 + topAdjust then
newLoc.locV = 0 + topAdjust
end if
sprite(spriteNum).loc = newLoc
updateStage
end repeat
end
on getBehaviorDescription me
return "Drop this on a sprite to make it draggable but constrained to the limites of the stage."
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA