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
Go to URL
DM Transition Pack 1
Light Up Game Controller
TranZtions
Stop all the sounds
Making the Projector Fill the Screen
More Maze Handlers
asUDP
cXtraDialogs
Graphic Puzzle Dragger
 

 

 

Behavior Linear Path Tracker

Added on 1/30/2001

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: JaiGanesh

A sprite dragged and dropped in any place on the screen traces its path back to its starting point in a linear path i.e in a straight line. This path is shown by a white line that is drawn along the path of the sprite.

--A sprite dragged and dropped in any place on the screen traces its path back to its starting point in a linear path i.e in a straight line. This path is shown by a white line that is drawn along the path of the sprite.
--This algorithm is based on the Simple Digital Differential Analyzer(Simple DDA).
--It is an incremenal method of drawing a line where each xunit and yunit coordinates to be plotted is incremented or decremented by a displacement value, dx and dy. Here, dx = dx and dy = dy .
--The starting position (coordinates) of the sprite is assigned as gx2 = 320 and gy2 = 240
--It must be understood here that gx2 will be the loch value and gy2 is the locv value to which the sprite traces its path back. These values may be changed in the startmovie or the users may provide a more interactive way of getting the values.

global gx1
global gy1
global gx2
global gy2
global lenest
-- Line Length estimate
global dx
global dy
-- Incremental Values
global xunit
-- Unit step generated in X-axis
global yunit
-- Unit step generated in Y-axis

on startmovie
  set the moveablesprite of sprite 2 to true
  updatestage
  member("org").duplicate(4)
  set the name of member 4 to "imgb"
  gx1 = 0
  gy1 = 0
  gx2 = 320
  gy2 = 240
  lenest = 0
  xunit = 0
  yunit = 0
  dx = 0.000
  dy = 0.000
  the floatprecision = 3
end


------------------------------------------------------------------------------------------------

global gx1
global gy1
global gx2
global gy2
global lenest
global dx
global dy
global xunit
global yunit

on mouseUp
  -- Simple DDA implementation.
  -- It generates unit steps in the direction of the largest motion.
  gx1 = the loch of sprite 2
  gy1 = the locv of sprite 2
  lenest = abs(gx2-gx1)
  if abs(gy2-gy1) > lenest then lenest = abs(gy2-gy1)
  dx = (abs(float(gx2)-float(gx1)))/lenest
  dy = (abs(float(gy2)-float(gy1)))/lenest
  xunit = gx1 + 0.5
  yunit = gy1+ 0.5
  repeat with i = 1 to lenest
    set the loc of sprite 2 to point(xunit,yunit)
    updatestage
    member("imgb").image.setPixel(xunit, yunit, rgb(255,255,255))
    if gx1 > gx2 and gy1 < gy2 then
      xunit = xunit - dx
      yunit = yunit + dy
    else if gx1 < gx2 and gy1 < gy2 then
      xunit = xunit + dx
      yunit = yunit + dy
    else if gx1 > gx2 and gy1 > gy2 then
      xunit = xunit - dx
      yunit = yunit - dy
    else if gx1 < gx2 and gy1 > gy2 then
      xunit = xunit + dx
      yunit = yunit - dy
    end if
  end repeat
  set the loc of sprite 2 to point(320,240)
  updatestage
end

 


Contact

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

Send e-mail