Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
StopWatch Timer
GetSoundLevel
PiMZ ImageImport
Dress Up
Hyper Midi
DirSaver
Check for DirectShow Installation
Display Full Screen
File Save as..
LiveCD
 

 

 

Behavior Jog Shuffle

Added on 4/19/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: DirkEismann

Use this piece of code to create a simple "JogShuffle". Drop it on a #bitmap/#vector sprite - and there you are!

-- JogShuffle Behavior
-- 18-04-2000, by dirk eismann
-- d.eismann@medienkonzepte.de
-- 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 spritenum
property pOrgLoc
property pAng
property pActive
property pHotSpots
property pRange


-- This is a quite simple implementaion of a JogShuffle
-- by clicking/dragging the jog it updates to a new angle
-- via simple angle calculations.
-- There are currently two parameters that can be edited in
-- the getPropertDescriptionList dialogue:

-- pHotList: a lineralist containing degree values that shall
--           represent the hotspots

-- pRange:   the "sensitive area" around a Hotspot in degrees.
--           eg: Hotspot #1 is 45 degree and the range is 10
--               the jog will react in the range from 35 to 55 deg



on beginSprite me
  
  -- pAng stores the actual angle (in degrees) of the jog
  pAng = 0.0  
  -- origin of the sprite  
  pOrgLoc = sprite(spritenum).loc
  sprite(spritenum).rotation = pAng
  
end beginSprite


on mouseDown me
  -- set the jog active
  pActive = 1  
end mouseDown


on mouseUp me
  -- deactivate the jog
  pActive = 0
end mouseUp


on prepareFrame me
  if not (the mouseDown and pActive) then
    pActive = 0
  else
    -- adjust the jog to the current mouse position
    me.mAdjustJog()
  end if
end exitFrame


on exitFrame me  
  -- check for hotspots, if there are any
  if pHotSpots <> [] then
    me.mCheckHotSpot()
  end if
  -- update the jog's rotation
  sprite(spritenum).rotation = pAng
end exitFrame


on mAdjustJog me
  -- get the new angle towards the mouse position
  x = the mouseH
  y = the mouseV
  
  -- transform to 'normalized' coordinates
  x = (- pOrgLoc[1] + x)
  y = (- pOrgLoc[2] + y) * -1
  
  -- although not mentioned in the Director manual,
  -- it *IS* possible to pass two values into the atan() function!!
  currRad = atan(x,y)
  
  -- convert it back to degrees so we can update the sprite's rotation
  currAng = me.mRadToDeg(currRad)
  
  -- a little conversion here if the angle gets a negative sign
  if currAng < 0 then
    currAng = 360.0 + currAng
  end if
  
  -- store the new angle into pAng
  pAng = currAng
  
end mAdjustJog


on mCheckHotSpot me
  -- check if the joggle is in a hotspot area
  repeat with spot in pHotSpots
    
    if abs(pAng - spot) < pRange then
      -- ** just for this demo, enter your special code for hotspot handling here **  
      put "Hotspot at" && spot && "degrees."
      exit repeat
      -- ** end of the demo code
    end if
    
  end repeat
end mCheckHotSpot


on mDegToRad me, degrees
  -- converts degrees to radians
  -- returns radians
  radians = degrees * pi / 180.00
  return radians
end mDegToRad


on mRadToDeg me, radians
  -- converts radians to degrees
  -- returns degrees
  degrees = radians * 180.00 / pi
  return degrees  
end mRadToDeg


on getPropertyDescriptionList me
  description = [:]
  
  description.addProp(#pHotSpots,[#comment:"Hotspots as degree-list:",#format:#list,#default:[45,90,270]])
  description.addProp(#pRange,[#comment:"'sensitive' area around each hotspot:",#format:#integer,#range:[#min:0,#max:10],#default:5])
  
  return description
  
end getPropertyDescriptionList


on getBehaviorDescription me
  
  descriptionText = ""
  put "JogShuffle Behavior, 18-04-2000, by dirk eismann, d.eismann@medienkonzepte.de" & RETURN after descriptionText
  put "-------------------------------------------------------------------------------" & RETURN after descriptionText
  put "This is a quite simple implementaion of a JogShuffle" & RETURN after descriptionText
  put "by clicking/dragging the jog it updates to a new angle" & RETURN after descriptionText
  put "via simple angle calculations." & RETURN after descriptionText
  put RETURN after descriptionText
  put "There are currently two parameters that can be edited in" & RETURN after descriptionText
  put "the getPropertDescriptionList dialogue:" & RETURN after descriptionText
  put RETURN after descriptionText
  put "pHotList: a lineralist containing degree values that" & RETURN after descriptionText
  put "               represents the hotspots" & RETURN after descriptionText
  put RETURN after descriptionText
  put "pRange:   the 'sensitive area' around a Hotspot in degrees." & RETURN after descriptionText
  put "               eg: Hotspot #1 is 45 degree and the range is 10" & RETURN after descriptionText
  put "               the jog will react in the range from 35 to 55 deg" & RETURN after descriptionText
  put "-------------------------------------------------------------------------------" & RETURN after descriptionText
  
  return descriptionText
  
end getBehaviorDescription

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail