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
QuickTime Silent Install
Reverse a list
Super Debugging
3D Watcher
Open Acrobat File
Custom Radio/Check Box
Simple projectile with gravity
Blend given sprite from 0 to given value
Direct Media Video Slider
Elapsed Time
 

 

 

Behavior Dragging multiple sprites

Added on 4/27/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: SylvainLangevin

To use it, you only have to attach the behavior to the master sprite, ie, the one that will become draggable. The behavior uses the right mouse button for dragging. "SLAVE SPRITES: Write here the number of each sprite that you want to be attached with the master sprite. Separate each number with a comma. Ex: 2,3,4.; RELATIVE SLAVES SPRITES: Check the box if the sprite number you wrote above are relative numbers compare to the master sprite. If they are absolute numbers, then uncheck the box. That could be useful if you have many boxes to move having each of them many sprites where all the sprites contained in each boxes would have the same relative number to the master sprite. Then you would only have to copy the same behavior to each boxes.; ALLOW VERTICAL AND HORIZONTAL MOVES: Check one of each to allow your sprites to be dragged in each or both ways.

-- Behavior for dragging multiple sprites
--Sylvain Langevin (Sylvain.Langevin@hec.ca)
--version 1.0
--22 avril 2000

---- properties --------------------------------
property pNumSpriteMaster   --sprite number of the sprite where the behavior is attached
property pNumSPritesSlaves  --sprite numbers of the slaves sprites that will follow the sprite master location
property pSpriteSlavesLocList  --location of all the slave sprites relative to the master sprite
property pRelAbsSlaves  --type of the sprite numbers for the slaves sprites: if 0 then absolutes ; if 1 then relative to the sprite of the master
property pVerticalMoveEnable  --allow vertical moves (0=no; 1=yes)
property pHorizontalMoveEnable  --allow horizontal moves (0=no; 1=yes)
property pNumSpriteSlavesList  --that list contains all the number of slaves sprites


-----------------------------
on beginSprite me
  
  pSpriteSlavesLocList = [:]
  pNumSpriteSlavesList = []
  
  --change pNumSPritesSlaves in list
  pNumSPritesSlaves = string(pNumSPritesSlaves)
  repeat with a = 1 to pNumSPritesSlaves.item.count
    pNumSpriteSlavesList.append(value(pNumSPritesSlaves.item[a]))
  end repeat
  
  pNumSpriteMaster = me.spriteNum
  
  --build the list for relative positions of the slaves sprites relative to the master sprite
  repeat with a = 1 to pNumSpriteSlavesList.count
    if pRelAbsSlaves = 0 then
      relLocH = sprite(pNumSpriteMaster).locH - sprite(pNumSpriteSlavesList[a]).locH
      relLocV = sprite(pNumSpriteMaster).locV - sprite(pNumSpriteSlavesList[a]).locV
      relLoc = [relLocH, relLocV]
      pSpriteSlavesLocList.addProp(pNumSpriteSlavesList[a],relLoc)
    else
      if pRelAbsSlaves = 1 then
        relLocH = sprite(pNumSpriteMaster).locH - sprite(pNumSpriteSlavesList[a] + pNumSpriteMaster).locH
        relLocV = sprite(pNumSpriteMaster).locV - sprite(pNumSpriteSlavesList[a] + pNumSpriteMaster).locV
        relLoc = [relLocH, relLocV]
        pNumSpriteSlavesList.addProp(pNumSpriteSlavesList[a] + pNumSpriteMaster,relLoc)
      end if
    end if
  end repeat
  
  
end




-----------------------------
on RightMouseDown me
  
  --put the mouseLoc in variable; it will help us to find if the mouse moved from the moment where the button has been clicked
  mousePosInitial = the mouseLoc
  
  --difference between the reg point of the sprite and the mouseLoc; keep the relation between them during dragging
  offset = the mouseLoc - sprite(pNumSpriteMaster).loc
  
  --enable dragging
  repeat while the rightMouseDown
    if mousePosInitial <> the mouseLoc then
      
      --check if vertical is disabled, then move horizontally only
      if pVerticalMoveEnable = 0 then
        sprite(pNumSpriteMaster).locH =  the mouseH - offset[1]
        newLoc = sprite(pNumSpriteMaster).loc
        
        --move the slaves sprites
        repeat with a = 1 to pSpriteSlavesLocList.count
          sprite(pSpriteSlavesLocList.getPropAt(a)).locH = newLoc[1] - pSpriteSlavesLocList[a][1]
        end repeat
        
        updateStage
      else
        --if horizontal is disabled, then move vertically only
        if pHorizontalMoveEnable = 0 then
          sprite(pNumSpriteMaster).locV =  the mouseV - offset[2]
          newLoc = sprite(pNumSpriteMaster).loc
          
          --move the slaves sprites
          repeat with a = 1 to pSpriteSlavesLocList.count
            sprite(pSpriteSlavesLocList.getPropAt(a)).locV = newLoc[2] - pSpriteSlavesLocList[a][2]
          end repeat
          
          updateStage
        else
          --move freely
          sprite(pNumSpriteMaster).loc =  the mouseLoc - offset
          newLoc = sprite(pNumSpriteMaster).loc
          
          --move the slaves sprites
          repeat with a = 1 to pSpriteSlavesLocList.count
            sprite(pSpriteSlavesLocList.getPropAt(a)).locH = newLoc[1] - pSpriteSlavesLocList[a][1]
            sprite(pSpriteSlavesLocList.getPropAt(a)).locV = newLoc[2] - pSpriteSlavesLocList[a][2]
          end repeat
          
          updateStage
        end if
      end if
    end if
  end repeat
  
end




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

on getPropertyDescriptionList
    
  set p_list = [ ¬
         #pNumSPritesSlaves: [ #comment:   "Slaves sprites:",                  #format:   #string, #default: "" ], #pRelAbsSlaves: [ #comment:   "Relative slaves sprites:", #format: #boolean, #default: 0 ], #pVerticalMoveEnable: [ #comment:   "Allow vertical moves:", #format: #boolean, #default: 1 ], #pHorizontalMoveEnable: [ #comment:   "Allow horizontal moves:", #format: #boolean, #default: 1 ]]
  return p_list  
end

on getBehaviorDescription
  return ¬
   "Description" & RETURN & "Behavior enabling to drag multiple sprite together while keeping their relative location. Could be useful, for example, if you make a remote control (not using a MIAW) and want to move all the sprite contained in the remote like a window. To use it, you only have to attach the behavior to the master sprite, ie, the one that will become draggable. The behavior uses the right mouse button for dragging."& RETURN &  "PARAMETERS:" & RETURN & "SLAVE SPRITES: Write here the number of each sprite that you want to be attached with the master sprite. Separate each number with a comma. Ex: 2,3,4."  & RETURN & "RELATIVE SLAVES SPRITES: Check the box if the sprite number you wrote above are relative numbers compare to the master sprite. If they are absolute numbers, then uncheck the box. That could be useful if you have many boxes to move having each of them many sprites where all the sprites contained in each boxes would have the same relative number to the master sprite. Then you would only have to copy the same behavior to each boxes." & RETURN & "ALLOW VERTICAL AND HORIZONTAL MOVES: Check one of each to allow your sprites to be dragged in each or both ways."  
end  

 


Contact

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

Send e-mail