Director News
Director Web Sites
Mailing Lists
News Groups
Project Examples
Useful Web Sites

Don't miss these
Sprite controls
3D SpeedPort Xtra
Dual Button With Rollover Effect
Universal Movie Pause Button
Sprite on/off
File Save Button
Wheel Mouse
Generic behavior to get Key State.
Vector Shapes - Create Spiral & Create Spiral Twist



Behavior Move sprite along mouse vector Behavior

Added on 4/29/2000


behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: DirkEismann

Moves any sprite(s) relative to the "mousevector" (the x/y change of the mouseLoc measured each frame)

-- Move sprite along mouse vector Behavior
-- 28-04-2000, by dirk eismann
-- feel free to use it in your projects
-- please send me a line if you modify it in a way that enhances its functionality

property pSprite
property pLoc
property pVector
property pEndLoc
property pStartLoc
property pStop

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

on getBehaviorDescription me
  descriptionText = ""
  put "Move sprite along mouse vector Behavior, 28-04-2000, by dirk eismann," & RETURN after descriptionText
  put "---------------------------------------------------------------------------------------------------" & RETURN after descriptionText
  put "Drop on any sprite(s)." & RETURN after descriptionText
  put "Everytime the mouse position changes, the sprite"s position is" & RETURN after descriptionText
  put "updated relative to the new mouse position." & RETURN after descriptionText
  put RETURN after descriptionText
  put "There is currently one parameters that can be edited in" & RETURN after descriptionText
  put "the getPropertDescriptionList dialogue:" & RETURN after descriptionText
  put RETURN after descriptionText
  put "pStop: boolean value. If set to true, the sprite stops movement" & RETURN after descriptionText
  put "          when the mouse "sleeps". otherwise the sprite keeps" & RETURN after descriptionText
  put "          on moving until the mouse position changes." & RETURN after descriptionText
  put "---------------------------------------------------------------------------------------------------" & RETURN after descriptionText
  return descriptionText
end getBehaviorDescription



36 South Court Sq
Suite 300
Newnan, GA 30263

Send e-mail