Random movement within an irregularly constrained sprite (EDITED)

(NEW EDIT AT BOTTOM)
So, basically, I'm making a little program that crudely simulates an ant colony. I have little tunnels the ant-sprites can travel down, as well as chambers, in an irregularly-shaped sprite.
I am not the most advanced at Director, but at least I've figured some things out. I found code on an open-source website (openspark, actually) that allows for an object to be dragged inside an irregular shape that has a matte ink.
It's all well and good that the ants can be dragged within this boundary, but is there any way to have them use a Random Movement and Rotation behavior that is confined by the same laws? Or is that impossible / extremely hard?
By the way, I already have a middleman behavior I use to toggle between dragging and random movement, so that does not factor into my question. I just need to know how to alter the Random Movement behavior so that it abides by the same constraint rules as my dragging behavior, if possible.
Here is the code I'm using for dragging. I made a couple edits from the original, but not much.
Don't worry about the canJumpGaps function of this code, as I am using a touch screen and it will never be used.
property spriteNum
property canJumpGaps    
-- set to TRUE on mouseDown if the shiftDown
property pSprite
-- this draggable sprite
property pConstraintSprite
-- sprite to which this sprite is constrained
property pConstraintAlpha
-- alpha channel image of constraining member
property pOffset
-- offset between this sprite's loc and the mouse
property pCurrentLoc
-- last known position of this draggable sprite with respect to the constraining sprite
-- EVENT HANDLERS --
on beginSprite(me)
  pSprite  = sprite(spriteNum)
  pConstraintSprite = sprite(1)
  -- We'll use the value of the alpha channel to detect holes in the sprite
  pConstraintAlpha  = pConstraintSprite.member.image.extractAlpha()
end beginSprite
on mouseDown(me)
  canJumpGaps = the shiftDown
  if not pCurrentLoc then
    -- The user has not yet dragged the sprite anywhere.  Find out its
    -- current position with respect to the constraint sprite.
    pCurrentLoc = pConstraintSprite.mapStageToMember(pSprite.loc)
    if not pCurrentLoc then
      -- The mouse is not over an opaque part of the constraint
      -- sprite.  It can't be dragged at all.
      exit
    end if
  end if
  -- Start dragging
pOffset = pSprite.loc - the mouseLoc
end mouseDown
on exitFrame(me)
  if not pOffset then
    -- The user is not dragging the sprite
    exit
  end if
if the mouseDown then
    me.mMoveSprite()
  else
    -- The user just released the mouse
   pOffset = 0
  end if
end exitFrame
-- PRIVATE METHOD --
on mMoveSprite(me) ---------------------------------------------------
  -- SENT BY exitFrame()
  -- ACTION: Calculates how near to the current mouseLoc the draggable
  --         sprite can be dragged.
  tMouseLoc = the mouseLoc + pOffset
  -- Find where the mouse is with respect to the constraint member
tImageLoc = pConstraintSprite.mapStageToMember(tMouseLoc)
  if voidP(tImageLoc) then
    -- The mouse is currently outside the constraint sprite.  Use a
    -- slower but more powerful method of determining the relative
    -- position.
    tLeft = pConstraintSprite.left
    tTop = pConstraintSprite.top
    tImageLoc = tMouseLoc-point(tLeft, tTop)
  else if canJumpGaps then
    -- Check if the mouse is over a non-white area of the constraint
    -- member
   tAlpha = pConstraintAlpha.getPixel(tImageLoc, #integer)
  end if
  if tAlpha then
    -- Let the mouse move to this spot
else -- Can't jump gaps or the mouse is over a gap
    -- Find how near the dragged sprite can get
    tDelta  = pCurrentLoc - tImageLoc
    tDeltaH = tDelta.locH
    tDeltaV = tDelta.locV
    tSteps = max(abs(tDeltaH), abs(tDeltaV))
    if not tSteps then
      -- The mouse hasn't moved since the last exitFrame
      exit
    end if
    tSteps = integer(tSteps)
if float(tSteps) <> 0 then
tStep  = tDelta / float(tSteps)
-- This makes sure I'm not dividing by zero.
else
tStep  = 1
end if
repeat while tSteps
-- Move one pixel towards the mouse
tSteps = tSteps - 1
tLoc = tImageLoc + (tStep * tSteps)
-- Test that we are still on an opaque area
tAlpha = pConstraintAlpha.getPixel(tLoc, #integer)
if not tAlpha then
-- We've gone a step too far: move back to an opaque area
tSteps = tSteps + 1
exit repeat
end if
end repeat
end if
-- Update the absolute and relative positions of the draggable
-- sprite.
tAdjust     = tSteps * tStep
pCurrentLoc = tImageLoc + tAdjust -- relative to constrain sprite
tMouseLoc   = tMouseLoc + tAdjust -- relative to the stage
-- Move the sprite
pSprite.loc = tMouseLoc
end mMoveSprite
Thank you SO incredibly much to anyone who can help. This is for a senior project of mine in undergrad, and I really appreciate any help I can get. My resources on Director are limited, especially for odd issues like this.
EDIT:
So I found out that a way to do collision detection in Director is by using getPixel().
I found this protected dcr file that is a perfect example of the way in which I want my ant objects to interact with walls:
http://xfiles.funnygarbage.com/~colinholgate/dcr/irregular.dcr
I've been trying to build a getPixel() collision detection mechanism for hours but have been unsuccessful.
Basically, what I want the behavior to do is... get the pixel color of the tunnel sprite (sprite 2) at the center of the ant sprite. If the pixel color is white (the transparent background color surrounding the tunnel shape), I want to tell the Random Movement and Direction behavior this:
pSprite.pPath = VOID
sendSprite(pSprite, #mNewPath)
pSprite.pRotate = VOID
sendSprite(pSprite, #mNewRotation)
This tells the Random Movement behavior to stop moving and determine a new path. The behavior should probably also offset the center of the sprite by a couple pixels when this happens so it is no longer over an opaque area and the Random Movement behavior won't get stuck.
Will this work? If not, could anyone help me in building a collision detection behavior based on getPixel? This doesn't seem like it'd be all that difficult - at least in theory.

Hi Roberto,
I had an experience, which defies most common sense about data modeling. Moving from a cube to a ODS and then back on to a cube to introduce delta on a BPS delta application. It is a long sad disappointing store. But I had 24 keys (I know 16 is the max, I combined 6 keys into a single filed also had the same fileds in the data fileds, use these combination keys to deal with 16 key max limitation and adjusted during transformation.
It did work, but later gave up due to some other functional issues and we realized it is a bad experiement due to everyones data understanding.
I am saying is 16 key limitation is an issue, you can overcome with combining couple of fileds into a single filed in the start routine, map it and reuse it later.
Hope this gives you some ideas.
Goodluck,
Alex (Arthur Samson)

Similar Messages

  • Follow sprite when the mouse is down, but randomly move when mouse is up?

    I have a sprite that has a Random Movement behavior.
    While the mouse is down, I want it to stop this behavior and initialize a Follow Sprite behavior instead.
    When the mouse is lifted, I want to stop the Follow Sprite behavior and reset/restart the Random Movement behavior.
    Openspark helped me out with a different version of a very similar behavior a long while back, which worked. It switched between Random Movement and Draggable. I tried to edit the code so that it would apply to Follow Sprite instead of Draggable, but it isn't working the way I thought it would.
    The order of behaviors on my sprite is as such:
    followSprite (Follow Sprite)
    moveToward (The behavior described above)
    randomMove (Random Movement)
    turnTowardsMouse (sprite faces mouse when it is clicked)
    Face Destination (if not facing mouse, sprite faces toward the randomized endpoints generated by randomMove)
    This is the moveToward behavior - the middleman that's supposed to be swapping between the two:
    property pSprite
    property pTouching
    on beginSprite(me)
      pSprite = sprite(me.spriteNum)
    end beginSprite
    on mouseDown(me)
      -- Overrule the Random Movement and Rotation behavior until the mouse
      -- is released. See the on prepareFrame() handler for the effect.
      pTouching = TRUE
    end mouseDown
    on prepareFrame(me)
      if pTouching then
        -- Block the event from reaching the Random Movement and Rotation
        -- behavior, so that only the Draggable behavior will work.
        if the mouseDown then
          stopEvent
        else
          -- The user has released the mouse.
          -- Start a new movement in the Random Movement and Rotation behavior.
          pSprite.pPath = VOID
          sendSprite(pSprite, #mNewPath)
          pSprite.pRotate = VOID
          sendSprite(pSprite, #mNewRotation)
          pTouching = 0
        end if
      end if
    end prepareFrame
    Can anyone help me figure this out?
    If you want to imagine a visual, it's essentially a touchscreen fish tank. Fish swim around randomly, but when someone is touching the screen, they approach the point of contact (which is defined by a tiny invisible sprite centered on the cursor).
    Once again, thank you so much to anyone who can help me out. This is part of a capstone undergraduate art project I am doing - and I am far more experienced in making the visuals than I am in coding. I am having to mostly tackle Lingo on my own. Any coding help I've received will be recognized (with permission) on my artist website as well as a thesis paper I am writing that will be published in May.

    As first steps at troubleshooting you could try an SMC reset and a PRAM reset:
    SMC Reset
    Shut down the computer.
    Unplug the computer’s power cord and disconnect peripherals.
    Press and hold the power button for 5 seconds.
    Release the power button.
    Attach the computers power cable.
    Press the power button to turn on the computer.
    Reset PRAM
    Shut down the computer.
    Locate the following keys on the keyboard: Command, Option, P and R.
    You will need to hold these keys down simultaneously in step 4.
    Turn on the computer.
    Press and hold the Command-Option-P-R keys. You must press this key combination before the gray screen appears.
    Hold the keys down until the computer restarts and you hear the startup sound for the second time.
    Release the keys.
    If that doesn't help, what OS are you running? Depending on the OS (Lion/Snow Leopard) will help determine the next step.

  • Keynote does not export Qucktime embedded movies within slides? Won't play

    I Have a Quicktime movie within one of my slides and when I export a Quicktime .mov file, that particular slide does not run the quicktime movie within it, just stays on the first frame?
    any ideas where I am going wrong?
    Message was edited by: thecount

    I think this is a limitation of the export -> quicktime option
    Keynote does all sorts of tricks to keep the file sizes small- and one thing really gets butchered are embedded quicktime movies- I have two almost show-stopper frustrations with this:
    1- quicktime movies do not loop when exported to quicktime (limitation of sprite track? will look around in live stage pro)
    2- all builds and movies must play in entirety before you can click through- this makes being able to skip around very cumbersome especially if using an indexed presentation

  • Attachment in OSX Mail are placed in random areas within e-mail

    Why is it when I add an attachment to Mail in OSX mail, it places the attachement in random places within my typed e-mail? Why doesn't it just attach blow in a designate spot? Instead I could type out a long e-mail and then when I place the attachment it puts it in some random spot within the e-mail, breaking up the formatting of the e-mail and making it look very unprofessional. I am working with OSX Lion but this also happens on non Lion Machines. Most of the files are Word 2011 files, some others are Excel, while also occuring with JPEG, and MPEG. Fix this please.

    Being users like yourself, we cannot really fix anything.
    But...
    As far as I can tell, the attachment always gets inserted where your cursor is currently located.
    You can, of course, move the attachment to any place you want, e.g., the end of the message, by dragging.
    charlie

  • How do I move mouselessly to next tune when editing Info?

    Often the CDDB gets it wrong with classical CDs and I frequently must edit the information in my library.
    For pieces, like symphonies, with multiple movements, I need to go into the Get Info screen (Apple-I) and edit the Name field. I usually will copy some corrected text to paste into part of the next tune’s Name field.
    Is there a way to use the keyboard to move to the next tune while editing Information fields? (This would be so much faster and easier than picking up my mouse and clicking on the Next Button.)
    Thank you in advance for any assistance.

    Tracy and Sara, thanks so much for the tip. In retrospect it seems so intuitive, but I kept trying to use the arrow keys in combination with alt-, ctrl-, etc.
    Since you’ve been so kind – and knowledgeable – may I impose a bit more: When you first go into the Information window, you’re put into the Summary area. What key or keys do you use to move to Info, Options, Lyrics, or Artwork?
    Once again thank you.
    BflatBlues
    PB G4 15 1.25ghz; LaCie 250Gb & Maxtor 300Gb; 20Gb 3G iPod; Mini 1.42ghz; Apple Mac OS X (10.4.3)

  • I have AVI files that I need to be MOV files so that I can edit them in Final Cut Pro. I am going to use Quick Time Pro for this....do I have to 'export' it or can I just 'save as', or is there even a difference? Thanks in advance for your help!

    I have AVI files that I need to convert to MOV files so that I can edit them in Final Cut Pro. I am going to use Quick Time Pro for this....When I have the files open in QT Pro do I have to 'export' it or can I just 'save as', or is there even a difference? Thanks in advance for your help!

    I strongly recommend you use compressor to do the conversion (if it will open the files - since quicktime will open them, it will more than likely do it.
    Compressor allows you to customize presets and save them and apply them to multiple files.  Although the interface may seem daunting, it's actually pretty simple.
    Even if you can edit the avi in fcp, it's not a good idea.  Liable to cause problems down the road. 

  • Centering a flash movie within Dreamweaver cs3 on Y axis

    I have published a movie in Flash cs3 which has generated an html document however the Flash movie is not automatically centered I have attempted to centrally align the movie within Dreamweaver cs3 by adding:
    <center> after the opening body tag and </center> befor the closing body tag
    This method has centered on the X axis but not the Y axis
    I would have put in a table or a div tag, but when I open the html doc in Dreamweaver I have no visible repressentation of the Flash movie in the design view as I would have if I had created an html document from scratch and draged the movie onto the page, all I can see is the "get flash" hypertext and some other text. I did actually experiment by creating a div tag and dragged my movie into it but ended up with two movies one sitting on top of the other when I ran it in a browser lol.  I'm quite intimdated by code and much prefer to work in the design view (wysiwyg and all that) which is quite restricting.
    Any advice for centering on the Y axis would be much apreciated, Thanks in advance, Dave

    I don't believe there is code to prevent this from happening
    on a client computer. The default is enabled my Microsoft, what
    should happen is a yellow bar should appear at the top of the
    browser which will allow you view the content.
    What might work is to use a program called Zinc by a company
    call Multidmedia Limited www.multidmedia.com. Search the site for
    samples, one of the samples is a Flash Browser this will run Flash
    a browser that you can use. You will need to change the URL a bit
    in the Flash code but it's very clear on how to do this.
    What this will do is run your web site in a Flash browser I
    did a quick test and I did not get any errors. The program will
    create an EXE file. I also believe they have a MAC version if you
    need one. With a simple "Autorun" call on the CD-ROM you could have
    this up and running in not time.
    Just be careful of how you call the pages. Since the web site
    is not running from a Web server you need to make sure that your
    links are local and not Site Root. The best way to test is to
    disconnect your computer from your internet and see how it runs.
    You want the CD to be self-contained and not have to get content
    from the web (your end user may be on a laptop and not connected).
    Good Luck

  • My ipod nano's click wheel randomly moves!

    Since I updated my ipod nano last night, after about a minute of it being turned on, the click wheel starts not to respond to my actions and randomly moves, this problem occurs on many menu's such as volume, selecting songs to listen to, games, and many more. I have tried resetting it, getting rid of the songs i added to it last night, recharging the battery, but with no luck. Please help; as I’m worried it could be a virus!
    Compaq   Windows XP  

    Is the Hold button on or off?
    Since resetting was a temporary fix, go to the Apple store. The staff there will let you know if you need a replacement or not as the iPod Nano is still under warranty.

  • Stopping Audio in movie within movie..?

    hello,
    If I create a captivate movie called XYZ, (series of slides,
    and/or full motion capture) add narration to it, publish it to swf
    format, and then create a new captivate movie called ABC which uses
    that swf on one of it's slides (i.e. a movie within a movie), how
    do I create buttons in ABC which will stop the audio of XYZ in case
    the learner wants to go to the next slide before XYZ finishes???
    Also, why does a wav file created in Audacity, and
    normalized, sound distorted in captivate? Is there a way around it,
    besides lowering the volume of my Audacity wav file?
    thank you
    Mike

    Mike said . . .
    quote:
    ... how do I create buttons in ABC which will stop the audio of
    XYZ?
    You don't. You create controls for movie XYZ
    within movie XYZ.
    quote:
    ... why does a wav file created in Audacity, and normalized,
    sound distorted in captivate?
    It doesn't - at least on all machines. Perhaps
    you are seeing the problem because of the file-format you are
    saving to (in Audacity). Can you describe what you mean by "sound
    distorted"? Your reference to lowering the volume indicates it is
    not necessarily being distorted, but being amplified excessively
    after import to Captivate . . .
    If that is the case, it seems to me that the simplest
    solution is exactly what you already suggested - lower the
    amplitude in Audacity . . .

  • Random Movie Clips loop

    Hey there.
    I have a question about randomizing Movie Clips:
    I am attaching an example where 12 movie clips will be called
    into stage.
    (movieA1, movieA2, movieA3....)
    I am trying to create a situation where instead of triggering
    "movieA1" and so on, the code will trigger:
    movieA1 OR movieB1
    movieA2 OR movieB2
    movieA3 OR movieB3 and so on......
    can anyone help here with how to apply it?
    Thanks!
    note that the attached code triggers AllMovies (MovieA's),
    MovieB's are not in code yet, only in the library, because I am not
    sure how to code such a thing.
    adamlewen

    All I posted was a replacement to the corresponding
    attachMovie portion of your code... as you had in your first post.
    If I've made a correct allowance for the wrapping it should be in
    the 6th line of code beginning with
    var Movie:MovieClip = _root["Movie"+i] =holder.attachMovie
    etc
    What I suggested is only making a change to the first
    parameter to include a
    B or no B in the library ID that's requested by the
    holder.attachMovie part.
    The way its set up (if you use this changed attachMovie) it
    will randomise each time that makeAllMovies is called.
    If I was doing something like this I'd be inclined to set up
    the holder clips once. And then load the randomised content clips
    inside on the setInterval call to something like your makeAllMovies
    function. I also think you'd need to use removeMovieClip for
    previously attached content clips before attaching each time as I
    don't think it just replaces ("overwrites") the old one. I've seen
    other posts where if you attachMovie the same library item with the
    same name in the same holder clip, you end up with 2 instances
    (flash apparently appends a number to one of them each time). If
    this is indeed the situation and happened each time, it would
    probably cause some problems.
    Don't know if that helps. Kglad or others may have more
    insight in this area where I've indicated uncertainty.

  • How can I place a video clip in CS6 within an irregular shape

    How can I place a video clip in CS6 within an irregular shape please

    Many thanks. I should have mentioned that I meant for the video to be an irregular shape also. However from what you said I have worked it out so thanks again for quick response. Pete.

  • How to play MOV files inside Windows Media Center Edition

    I've installed QT Pro, but am not able to play MOV files inside Windows Media Center Edition (MCE). Under "My Videos" from the MCE main interface, I can see the files, but once selected, error message indicates unknown/unplayable file type.
    How do I get my MOV files to play inside Windows MCE??
    Marc

    Quote from: cosmosk on 05-April-05, 22:29:47
    I don't use MSI's MC application so I can't directly answer your question.
    However both Win DVD 6 and PowerDVD6 play them just fine by launching the ts.ifo file.
    Yes, I know that, but that means that I should use at least two applications. I need only one front end to launch all my media files, inluding ripped DVD files, not as separate VOBs but as whole movies decribed in IFO files.
    Kiero

  • Have just upgraded to Lion.  In all applications a box now appears that encloses topics, etc on the screen.  It is a problem as it also randomly moves around the screen.  Have no idea what the purpose is and want to get rid of it. Scroll does not work.

    Just upgraded to Lion. Scroll does not respond. Have tried altering preferences. Will not fix. In all applications, including this page, a box appears and seems to randomly move around the screen, resting wherever I begin to work. How can I turn this off and get scroll to work normally?

    Have a look at System Preferences, Accessibility, VoiceOver.
    (Command - F5).
    charlie

  • When working mouse will randomly move even when I'm not moving it

    When working on my computer my mouse will randomly move even when I'm not moving it. It is like I have a ghost mouse that is moving across the screen by itself. I checked and made sure screen sharing isn't on. It occurs randomly from what I can tell. It happened twice tonight where I'm on a window with my hand on the mouse and the cursor will move up to the top of the screen and then to the very left (which will turn on my screen saver). I will make me feel better if someone has seen this to. It happens very quickly and I can get control of my mouse. I have seen this off and on for a while. Anyone else?

    I have the same issue.
    It is a wired Mighty Mouse on a 24" iMac. My Macbook Pro with Wireless Mighty Mouse has never had an issue that I can recall, only the desktop.
    It's pretty **** annoying to be fencing something in on Photoshop and suddenly your mouse is up in the corner of the screen and you've selected half your picture.
    Anyone have any thoughts? What are the common denominators here?
    As I said, 24" iMac running 10.5.5(although it has been happening since I purchased the computer somewhere around 10.5.3) Corded Mighty Mouse, Aluminum Keyboard. Can't think of any other relevant information....

  • Why do I get "not connected to Internet " when I try to move within a website?

    I am using Verizon hotspot to connect my laptop with internet. Never had problems until IOS 8 came out. My laptop is XP but I don't want a new computer yet! Since I downloaded 8 on my phone my laptop does not work properly! I can get on various websites, but when I try to move within the website I receive on a large screen "no internet connection" but I am still connected to the internet. When I use my computer on a free wifi service I don't have this problem. What is going on? Help Me Please!!!

    '''[https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode Start Firefox in Safe Mode]''' {web link}
    While you are in safe mode;
    Type '''about:preferences#advanced'''<Enter> in the address bar.
    Under '''Advanced,''' Select '''General.'''
    Look for and turn off '''Use Hardware Acceleration'''.
    Poke around safe web sites. Are there any problems?
    Then restart.
    Some added toolbar and anti-virus add-ons are known to cause
    Firefox issues. '''Disable All of them.'''

Maybe you are looking for

  • To exclude Open Order Value in Credit exposure for Delivery credit Block

    Dear All, I have assigned the credit Limit block at the Delivery Level. For the credit Exposure, i have removed the ticked for Open Sales Orders. But when i created sales Order, that open order value get added to the exposure. I want to have only the

  • How to move iTunes from Mac to PC (via external drive)

    I would like to copy my iTunes library from my home iMac to a PC laptop (I know, don't ask, it's a work tool) - without clogging that work PC with all the music data, so I am thinking external drive. Here are my questions: first, how do I need to for

  • E-MU 0202 - unsuccessful firmware update.

    I have E-MU 0202 usb interface and I tried to update firmware from 4 to 8th version. When i did it, the card became unable to boot - the "power" indicator blinks, I can hear clicks in headphones as if card reboots over and over again. Windows can't d

  • Items given for free

    Hi, I need a list of the most commonly used scenarios where an item is given away free. And then  a detailed listing of the pros and cons... plus what happens to the accounting document... the invoice and other things?

  • Business One and Citrix

    Iu2019d like to start a general discussion regarding the use of Business One over Citrix Presentation Server/XenApp.  Specifically, how best to design this type of solution and how to overcome any obstacles that may result. For example, my company is