2 Replies Latest reply on Jul 28, 2010 3:43 PM by GCMNajjar

    Intersect Function Problem

    GCMNajjar Level 1

      I am using the intersect function (Dir 8.5) to detect the collision of two sprites.  Both sprites are produced in Photoshop as png.  The trouble is that the function sometimes works and other times it doesn't.  I am not sure if it is the png produced by PS or Director.


      The PNGs are produced exactly in the same way in PS.

      I import the files into the cast

      Place in the score

      Set the ink of each sprite to matte at 100% transparency

      With the sprites outlines intersecting each other, I use the command "put sprite 2 intersects sprite 3" in message box

      Sometime the result is 0 and other times it is 1.  When I move Sprite 1 outside the Quad of sprite 2 then I consistently get 0.

      I then reproduce the same graphic for sprite 1 (EXACTLY!).

      Try the same procedure as above, now I get 1 no mater where sprite 2 is.


      What is the proper format for a graphic that I can use the MATTE ink with.  I have now tried .psd and .png with no luck.  .jpe doesn't work as there is no transparency.


      Am I missing something?  I searched the forum and couldn't find anything like this with the intersect function.


      any ideas or help will be most appreciated.



        • 1. Re: Intersect Function Problem
          Chunick Level 3

          You need to also set the alphaThreshold property of the member... you can do it manually in the Property Inspector under the Member tab or programmatically using a behavior attached to your sprite, something like this:

          on beginSprite me

            sp = sprite(me.spriteNum)

            mem = sp.member

            sp.ink = 8 -- set to matte ink

            mem.alphaThreshold = 128 -- too high and the whole image is treated as transparent.



          from the help docs: alphaThreshold - Bitmap cast member property; governs how the bitmap’s alpha channel affects hit detection. This property is a value from 0 to 255, that exactly matches alpha values in the alpha channel for a 32-bit bitmap image.


          btw, it's best to use 32-bit PNGs with an alpha layer. For one, the PSD is premultiplied with white which can cause a haloing effect.


          To see collision detection using this method view my example here: http://collab.directorforum.com/Collision_Detection_Scripts_for_2D_Games

          • 2. Re: Intersect Function Problem
            GCMNajjar Level 1
            Thanks Joshua,
            I will try your idea.  In the meantime, I found an interesting solution by detecting the pixel color and therefore I am able to detect collision between sprites very presisely.  However this is solower than "intersect" so I will try you suggestion/