how to moving sprites together as a group and an example of inter-Behavior communication
sprites BehaviorTalk

  grouping sprites
>I have a kind of filmstrip with different pictures after eachother. I
>want them to remain on there relative possitions and when you move the
>mouse over on of the pictures they should all move up or down, depending
>on how you move the mouse.
>Can somebody give me some hint in the right direction with this?
>I suppose i should make a behavior and attach it to each sprite, but how
>do i send a mousemessage to all of them, so they can move together?
>Gratefull for your help

With the behavior below you can have one or several named groups of sprites 
which each move as if they were just one single sprite if dragged with the 
mouse (and set to moveable in the score) or just one sprite of the group is 
moved by lingo.
I took it from a context where the group would communicate with vertical and 
horizontal scrollers according to its rect so there may be some code left that 
is not actually needed here.

Hope it helps!

property myInited,myLOurSprites,myMagicSpell,mySprite, myLastLoc

on getPropertyDescriptionList me
  set theProps to [:]
  set c to "Please name the group this sprite belongs to"
  set f to #symbol  
  set d to #aGroup
  set typeProps to [#comment: c, #format: f, #default: d]
  addProp theProps, #myMagicSpell, typeProps
  return theProps

on getBehaviorDescription me
  set line1 to "   This behavior makes a group of sprites move together if one of them is moved." & RETURN  
  return line1

on beginSprite me
  -- init vars 
  set mySprite = the spritenum of me
  set myLOurSprites = []
  if voidP (myMagicSpell) then set myMagicSpell = #wonko 

on enterframe me
  -- Init not done?
  if not (myInited) then 
    sendallSprites (#initialize,myLOurSprites,myMagicSpell)
    tellGroupOurSprites me
  end if
  -- things to be done once per group and frame
  -- the last one now will be later the first
  if getLast(myLOurSprites)= mySprite then
    -- do things for the group    
  end if

on exitFrame me
  set myLoc = getLoc (me)
  set myVec = myLastLoc - myLoc
  if myVec = point(0,0) then return
  set myLastLoc = myLoc
  tellGroupMove me,myVec

on initialize me,dL,dSpell
  if myMagicSpell <> dSpell then return
  set myInited = TRUE
  append dL,mySprite
  set myLastLoc = getLoc (me)

on setLOurSprites me,dL
  set myLOursprites = dL  

on tellGroupOurSprites
  repeat with dSprite in myLOurSprites
    if dSprite = mySprite then next repeat
    sendSprite dsprite,#setLOurSprites,myLOurSprites
  end repeat

on tellGroupMove me,dVec
  repeat with dSprite in myLOurSprites
    if dSprite = mySprite then next repeat
    sendSprite dsprite,#moveSprite,dVec
  end repeat

on tellGroupJoinRects me,dRect
  repeat with dSprite in myLOurSprites
    if dSprite = mySprite then next repeat
    set dREct = sendSprite (dsprite,#JoinRects,dRect)
  end repeat
  return dRect


on joinRects me,dRect
  return union ( dRect, the rect of sprite mySprite)

on moveSprite me,dVec
  set dLoc = getLoc(me)-dVec 
  setLoc me, dLoc
  set myLastLoc = dLoc

on getLoc me,dSprite
  if voidP(dSprite) then set dSprite = mySprite
  return the loc of sprite dSprite

on setLoc me,dLoc
  set the loc of sprite mySprite to dLoc


Home shock + cgi Bits 'n pieces Director Lingo Shocklets Contact