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
Exit Browser
Check For Asset
HJ Install
File open/save dialog
OpenDBC
Set Quality of a Flash Sprite
Send OSA Script
ExpressMail Xtra for Authorware and Director
Check QuickTime Version
Movie Slider Control
 

 

 

Behavior Graphic Puzzle Dragger

Added on 6/10/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: JohnDowdell

This behavior solves the map problem, the jigsaw problem, the "let"s dress Barbie!" problem, and others. When dragged atop a sprite you can later move the sprite and it will remember its "solved" position. When the enduser moves all sprites back in their solved positions play will proceed to the next label, or any desired label.

--This behavior solves the map problem, the jigsaw problem, the "let"s dress Barbie!" problem, and others. When dragged atop a sprite you can later move the sprite and it will remember its "solved" position. When the enduser moves all sprites back in their solved positions play will proceed to the next label, or any desired label.
--The routine handles asynchronous dragging by adding the behavior itself to the actorList, and removing the behavior from the actorList when the mouse is released or when the piece snaps into place. This lets you run other animations in the background and use the computer normally, in a way that tight repeat loops do not.
--The "CheckForCompletion" routine is interesting, because it checks for all other sprites which share that behavior, and asks them whether they"re already in correct position. It does this by passing a list in the sendAllSprites broadcast, which avoids having to get values returned from the sprite broadcast call. (Unlike numeric or string variables, all variables which point to a list point to the same object.)
--Why the long "DraggedPuzzlePiecesBehavior_CompletionQuery" name? Because this message is broadcast to all sprites. Specifying the castLib and behavior avoids possible crosstalk with other behaviors written by other people. You could broadcast a simple "CompletionQuery" message to all sprites in your own work, but a non-scripting designer may be puzzled if they use another behavior that has a handler of similar name. Unique names reduce crosstalk.
--You can customize this in many ways... the simplest is in the "CheckForCompletion" method, where click sounds or help strings can be added.
property spriteNum, correctLoc, nextSequence, dragOffset, snapDistance

on mouseDown me
  set dragOffset to the loc of sprite spriteNum - the clickLoc
  add the actorList, me
end

on mouseUp me
  deleteOne the actorList, me
end

on stepFrame me
  set newLoc to point(the mouseH, the mouseV) + dragOffset
  set the loc of sprite spriteNum to newLoc
  set delta to newLoc - correctLoc
  if (abs(the locH of delta) < snapDistance) then
    if (abs(the locV of delta) < snapDistance) then CheckForCompletion(me)
  end if
end

on CheckForCompletion me
  set the loc of sprite spriteNum to correctLoc
  --  puppetSound "click"
  --  put "That"s right! That"s " & the name of member (the member of sprite spriteNum) & "!" into field "display"
  set success to [TRUE]
  sendAllSprites #DraggedPuzzlePiecesBehavior_CompletionQuery, success
  if min(success) = TRUE then go nextSequence
  deleteOne the actorList, me
end

on DraggedPuzzlePiecesBehavior_CompletionQuery me, success
  add success, (the loc of sprite spriteNum = correctLoc)
end

on getPropertyDescriptionList me
  if (the currentSpriteNum <> 0) then
    set myLoc to the loc of sprite (the currentSpriteNum)
    set theProps to [:]
    
    set c to "Go to this label when all are in place: "
    set f to #marker
    set d to "next"
    addProp theProps, #nextSequence, [#comment: c, #format: f, #default: d]
    
    set c to "How many pixels away before it snaps into place?"
    set f to #integer
    set d to 10
    addProp theProps, #snapDistance, [#comment: c, #format: f, #default: d]
    
    set c to "btw, here"s the target location for this graphic: "
    set f to #point
    set d to myLoc
    addProp theProps, #correctLoc, [#comment: c, #format: f, #default: d]
    
    return theProps
  end if
end

on getBehaviorDescription me
  set line1 to "This behavior is for puzzle pieces that you wish to drag around and snap into place. When all the pieces are assembled then play proceeds to the next sequence, or to any labeled frame you wish." & RETURN
  set line2 to "" & RETURN
  set line3 to "To use:" & RETURN
  set line4 to "1)  Assemble the puzzle on the screen in its "solved" arrangement." & RETURN
  set line5 to "2)  Drag this behavior onto each piece, one at a time. You can just click "OK" on the Parameter Dialog, or you can tweak the label to go to or the snapping distance. (You do not need to adjust the "target location" field.)" & RETURN
  set line6 to "3)  Once each piece has this behavior, then mix up the pieces as you wish. The behavior will remember where they should go." & RETURN
  set line7 to "" & RETURN
  set line8 to "The behavior script itself has additional info on script construction, if you wish to customize this behavior further." & RETURN
  set line9 to "" & RETURN
  set line10 to "" & RETURN
  return line1 & line2 & line3 & line4 & line5 & line6 & line7 & line8 & line9 & line10
end

 


Contact

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

Send e-mail