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
XTinyadoDB xtra
Generic Countdown Timer
bubbleSortForStrings AND bubbleSortForStringLists
Advanced Lingo for Games
Text Drop Shadows (and a moving light)
Eat That Dot
Double Char Fix - D 7.0
True Lingo Color Wheel 1.0
DirGames Discussion List
authoring method docSprite()
 

 

 

Article Creating a Marquee Tool

Added on 11/8/1999

 

Compatibilities:
D7 D8 Mac PC Shockwave

Rating:

Author: MediaMacros (website)

I'd like to simulate a selection marquee or "dancing ants". Is this possible?

Get the source
Hey.  We are working in Director.  Of course this is possible.  The answer will actually come from a rather unlikely and under utilized source as well.  For this example we are going to dive into Director's tile-able patterns for a little help.

First lets look at what we want to do.  Basically we want to create a rectangle between 2 points on the stage.  Pretty easy with a quick-draw rectangle, but we need only the border and we want the side to be different from the top and bottom.  The sides will have horizontal bands, while the top and bottom will be vertical.  We also want these bands to be animated.  That will rule out scaling a bitmap, and eliminates the use of a single rectangle, but we can fake this with 5 pieces.  What if we make a rectangle out of 4, 1 pixel wide quick draw rectangles?  Then we can assign a different pattern to each and dynamically make our marquee.  

Ok, lest start with the tile tools.  Make a basic quick-draw shape and click the "Pattern button" located just below the color selector on the tool pallet.  This pops up a nice little dialog.  For this example I will set up 4 patterns.  2 frames for each of the 2 types (top and sides).  We can create a simple pain cast member of horizontal and vertical stripes and then assign them as a pattern.  To animate them just offset the square the pattern uses by a few pixels.

Now we need to get the number of the patter we are using.  Assign a pattern to a quick-draw member and type the following in the message window...

put member(x).pattern

Now that we are armed with this number we can feed our behavior all the numbers it needs to run the "loop".  For the behavior we will assign it a property that will determine if the sprite is the top, left, bottom, right, or background sprite.  The background will handle the mouse clicks and use the sendAllSprites command to tell the other shapes where to move.  In the mouseDown handler we check to see if the clicked sprite is the background, and if so start a repeat loop while the mouse is held down. This calculates the rectangle formed by the initial click point and the current mouse location and sends this to all the sprites.  The take this info and update their rectangle.  When the mouse is released the calculate one last time, or if the 2 locations are the same the move off the screen entirely.  As an added bonus there is a global variable that defines the rectangle that the marquee borders to be used by other handlers.

Now all we need to do is to loop the marquee sides to make our little ants dance.  Using a string that is a list of all the patterns to use we can cycle through and swap out the pattern on each exitFrame.  This gives a nice illusion of a standard Marquee.  The completed code is below.

--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)

property spriteNum, whatPiece, patternList, whatPattern

global selectedRect

on getPropertyDescriptionList me
  p_list = [:]
  p_list.addProp(#whatPiece, [#format : #symbol, #comment : "Which side of the marque:", #default : #top, #range : [#Top, #Left, #Right, #Bottom, #BG]])
  p_list.addProp(#patternList, [#format : #string, #comment : "Pattern Numbers:", #default : "57,58"])
  return p_list
end

on mouseDown me
  if whatPiece = #bg then
    --it is the bg, set a new marque
    startPoint = the mouseLoc
    repeat while the stillDown
      mousePoint = the mouseLoc
      if mousePoint.locH > sprite(spriteNum).rect.right then
        mousePoint.locH = sprite(spriteNum).rect.right
      else if mousePoint.locH < sprite(spriteNum).rect.left then
        mousePoint.locH = sprite(spriteNum).rect.left
      end if
      if mousePoint.locV > sprite(spriteNum).rect.bottom then
        mousePoint.locV = sprite(spriteNum).rect.bottom
      else if mousePoint.locV < sprite(spriteNum).rect.top then
        mousePoint.locV = sprite(spriteNum).rect.top
      end if
      hList = [startPoint.locH, mousePoint.locH]
      vList = [startPoint.locV, mousePoint.locV]
      sort(hList)
      sort(vList)
      theRect = rect(hList[1],vList[1], hList[2], vList[2])
      sendAllSprites(#makeMarque, theRect)
      updateStage
    end repeat
    if startPoint = the mouseLoc then
      selectedRect = rect(0,0,0,0)
      sendAllSprites(#moveOff)
    else
      mousePoint = the mouseLoc
      if mousePoint.locH > sprite(spriteNum).rect.right then
        mousePoint.locH = sprite(spriteNum).rect.right
      else if mousePoint.locH < sprite(spriteNum).rect.left then
        mousePoint.locH = sprite(spriteNum).rect.left
      end if
      if mousePoint.locV > sprite(spriteNum).rect.bottom then
        mousePoint.locV = sprite(spriteNum).rect.bottom
      else if mousePoint.locV < sprite(spriteNum).rect.top then
        mousePoint.locV = sprite(spriteNum).rect.top
      end if
      hList = [startPoint.locH, mousePoint.locH]
      vList = [startPoint.locV, mousePoint.locV]
      sort(hList)
      sort(vList)
      theRect = rect(hList[1],vList[1], hList[2], vList[2])
      sendAllSprites(#makeMarque, theRect)
      selectedRect = theRect
    end if
  end if
end

on beginSprite me
  selectedRect = rect(0,0,0,0)
  moveOff()
  whatPattern = 1
end

on makeMarque me, whatRect
  case whatPiece of
    #top :
      sprite(spriteNum).rect = rect(whatrect[1] - 1, whatRect[2] - 1, whatrect[3] + 1, whatRect[2])
    #bottom :
      sprite(spriteNum).rect = rect(whatrect[1] - 1, whatRect[4], whatrect[3] + 1, whatRect[4] + 1)
    #left :
      sprite(spriteNum).rect = rect(whatrect[1] - 1, whatRect[2] , whatrect[1] , whatRect[4])
    #right :
      sprite(spriteNum).rect = rect(whatrect[3], whatRect[2] , whatrect[3] + 1, whatRect[4])
  end case
end

on moveOff me
  if whatPiece <> #bg then
    sprite(spriteNum).rect = rect(-1000, -1000, -1000, -1000)
  end if
end

on exitFrame me
  if whatPiece <> #BG then
    the itemDelimiter = ","
    whatPattern = whatPattern + 1
    if whatPattern > patternList.item.count then whatPattern = 1
    sprite(spriteNum).member.pattern = integer(patternList.item[whatPattern])
  end if
end

on getBehaviorDescription me
  describe = "This behavior simulates a marque tool in Director."
  describe = describe & return & "Make 2 quick-draw squares and create custom patterns for horizontal and vertical stripes. Make at least 2 frames of each, offset slightly."
  describe = describe & return & "Place 2 of each quickDraw shapes on the stage and drop the behavior on top. Assign the number of the patters(get it with put member(x).pattern) and then apply it to a background sprite as well. The resulting rectangle is stored in the global variable selectedRect"
  describe = describe & return & return & "An example is available in articles section of MediaMacros at www.mediamacros.com/howto.shtml"
  return describe
end

 


Contact

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

Send e-mail