on beginSprite me
-- sprite reference
pSprite = sprite(me.spritenum)
-- sprite position reference
pLoc = pSprite.locH
-- for calculating the mouse movement
pStartLoc = the mouseLoc
pEndLoc = pStartLoc
-- current vector
pVector = point(0,0)
end beginSprite
on prepareFrame me
-- store the current mouse position
pStartLoc = the mouseLoc
end prepareFrame
on exitFrame me
-- as soon as the mouse stops, store the new position
if the lastRoll > 4 then
pEndLoc = the mouseLoc
end if
if pStartLoc <> pEndLoc then
pVector = pStartLoc - pEndLoc
-- because the sprite may behave strange if the movement is minimal
-- the vector is set to 0,0 if one component"s value is 1 or less
if pVector[1].abs <= 1 and pVector[2].abs <= 1 then
pVector = point(0,0)
end if
end if
pSprite.loc = pSprite.loc + pVector
if pStop then
-- if the sprite should stop immediately, set the vector back to 0,0
pVector = point(0,0)
end if
end exitFrame
on getPropertyDescriptionList
description = [:]
description.addProp(#pStop,[#comment:"Stop movement if mouse stops movement:",#format:#boolean,#default:false])
return description
end getPropertyDescriptionList