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
Text Shifting
Find windows directory or Macintosh System folder
Drag sprite around a snap grid
Wait For Media Ready
Text Services API
Arca Database Xtra
Jaw Wars
Install font
Scroll Thumb
Face Mouse-Alphamania
 

 

 

Behavior Follow the leader

Added on 4/19/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: AlanQueen

Instructions: Designate one sprite to be the LEADER. Put as many other sprites in adjacent channels which will be the FOLLOWERS. Make sure the LEADER sprite is in the highest sprite channel.Drop this behavior on all FOLLOWERS. Move the leader through your own lingo, or by setting it as MOVEABLE in the score.

Download PC Source    Download Mac Source
property pLeader -- Which sprite to follow.
property pVLag -- How much to "lag" behind the leader vertically
property pHLag -- How much to "lag" behind the leader horizontally
property pActive -- This turns on or off the pVLag and the pHLag


on beginSprite me
  me.pLeader = me.spriteNum + 1 -- Which sprite to follow.
  me.pVLag = (random(2) + 1) * .1 -- How much to "lag" behind the leader vertically
  me.pHLag = (random(2) + 1) * .1 -- How much to "lag" behind the leader horizontally
  me.pActive = [1,1] -- This turns on or off the pVLag and the pHLag
end beginSprite

on exitFrame me
  vLeaderLoc = sprite(me.pLeader).loc -- Find your leader"s position
  vMyLoc = sprite(me.spriteNum).loc -- Get your position
  vHDif = vLeaderLoc[1] - vMyLoc[1] -- Find the horizontal difference from the leader
  vVDif = vLeaderLoc[2] - vMyLoc[2] -- Find the vertical difference from the leader
  
  -- Follow the leaders" position with a horizontal lag
  if me.pActive[1] then sprite(me.spriteNum).locH = vMyLoc[1] + (vHDif * me.pHLag)
  -- Follow the leaders" position with a vertical lag
  if me.pActive[2] then sprite(me.spriteNum).locV = vMyLoc[2] + (vVDif * me.pVLag)
end exitFrame


on getBehaviorDescription me
  vDesc = ¬
"Description: This behavior will make an unlimited number of sprites follow a LEADER sprite, with¬
a definable LAG, which can make for some interesting effects, such as a snake, or a¬
streamer, or a kite. " & RETURN & RETURN & ¬
"Instructions: Designate one sprite to be the LEADER.¬
Put as many other sprites in adjacent channels which will be the FOLLOWERS.¬
Make sure the LEADER sprite is in the highest sprite channel.¬
Drop this behavior on all FOLLOWERS. Move the leader through your own lingo,¬
or by setting it as MOVEABLE in the score. Demo and source at: ¬
http://www.mindspring.com/~alqueen/FollowTheLeader.dir"
  return vDesc
end getBehaviorDescription

 


Contact

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

Send e-mail