Articles Archive
Articles Search
Director Wiki

Dragging multiple sprites

December 25, 1997
by Alex Zavatone

Here is some quick code to create a bunch of objects that drag as one. This code is to be called from a sprite's mouseDown script and does have a repeat loop which will suspend most other background events on the Mac but not on Windows.

All the sprites should be ordered in the score one after the other with the sample code being called from the first sprite's mouseDown. The list of sprites to drag is relative to the starting sprite number and is defined in the list called mySprites. Each of these sprites are puppeted on mouseDown and left that way on mouseUp. During fast dragging, there are some flickers as sprites reposition themselves. I can't find anywhere in the code that would cause this but it's rather minor. The line where mouseLoc is defined is an attempt to minimize this misbehavior.

Also, my standard disclaimer of "it could be written better" always applies but hey, it works, it's free, have fun! Oh, this should work in Director 4, 5 and 6.


-- Copyright 1998 by Zav - Alex Zavatone for Director-Online
-- use as you see fit and please give credit if used a project

on Drag
   set mySprites = [0,1,2,3,4,5,6,7]
   set oldLocations = [:]
   set mySprite = the clickOn
   set myLoc = point(the mouseH, the mouseV)
   repeat with mySpriteNum in mySprites
      set theSprite = mySprite + mySpriteNum
      puppetSprite theSprite, 1
      addProp oldLocations, theSprite, ¬
         the loc of sprite theSprite - myLoc
   end repeat
   repeat while the mousedown
      set mouseLoc = point( the mouseH, the mouseV)
      repeat with mySpriteNum in mySprites
         set theSprite = mySprite + mySpriteNum
         set the loc of sprite theSprite = ¬
            getProp(oldLocations,theSprite) + mouseLoc
      end repeat
   end repeat

A demo movie (used to create the Shockwave movie) is available for download (SIT or ZIP).

A Director user since 1987, Alex (Zav) Zavatone has worked on the engineering teams for both Director and Shockwave, 4, 5, 6 and 7. Recent investigations find him developing foundation classes for Director with asynchronous process management and other life threatening activities. In its early days, he had something to do with this Internet thing known as "DOUG". A noted ne'erdowell, slacker and laggard, Mr. Zavatone is nonetheless is trusted by children, small animals and the elderly. In his spare time, Mr. Zavatone rehabilitates lame desert trout.

Copyright 1997-2019, Director Online. Article content copyright by respective authors.